From 07653129fc84e5d9800c15845019485ff15d3cdd Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Mon, 23 Nov 2026 19:23:38 +0800 Subject: [PATCH] fix(vcs): keep the log mounted while another Git tab is shown Switching from Console or Worktrees back to Log rebuilt the commit list, graph, branch tree and details, and reloaded the log, refs and branches. The last log tab shown now stays mounted, hidden with content-visibility, so switching back to it is a plain show. --- src/features/vcs/GitLog.module.css | 17 +++++++++++++++++ src/features/vcs/GitLog.tsx | 28 +++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/features/vcs/GitLog.module.css b/src/features/vcs/GitLog.module.css index 2221b19280..eb5c56a858 100644 --- a/src/features/vcs/GitLog.module.css +++ b/src/features/vcs/GitLog.module.css @@ -1,9 +1,26 @@ .root { + position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; } +/* Absolute in both states, so hiding and showing the log doesn't lay it out again. */ +.logHost { + position: absolute; + inset: 0; + display: flex; + flex-direction: column; +} +.logHidden { + content-visibility: hidden; + z-index: -1; +} +/* WebKit leaves a stale selection highlight on a subtree whose rendering was skipped when the selection cleared. */ +.logHidden[data-selection] { + content-visibility: visible; + opacity: 0; +} .headerTabs { min-width: 0; border: 0; diff --git a/src/features/vcs/GitLog.tsx b/src/features/vcs/GitLog.tsx index e1e271e514..73366e220f 100644 --- a/src/features/vcs/GitLog.tsx +++ b/src/features/vcs/GitLog.tsx @@ -14,6 +14,7 @@ import { useFrozenWhileWindowResizes, } from "@/ui"; import { copySelectionOnKeyDown } from "@/ui/selectableText"; +import { useSelectionVisibility } from "@/ui/useSelectionBoundary"; import { spanStyle } from "@/ui/ansi"; import clsx from "clsx"; import { useContext, useEffect, useLayoutEffect, useRef, useState } from "react"; @@ -34,6 +35,7 @@ import { LogScope } from "./LogScope"; import { closeLogTab, initLogBranchFilter, + isLogTab, logState, refsSignature, reloadLog, @@ -85,6 +87,15 @@ export function GitToolWindow() { // window drag; they follow the window once it stops. const root = useRef(null); useFrozenWhileWindowResizes(root); + // The last log tab shown stays mounted (hidden, keeping its layout) while another tab is shown, + // so switching back to it neither rebuilds its rows, graph and branch tree nor reloads it. + const logTabs = useGitLog((s) => s.logTabs); + const logShown = isLogTab(shown, logTabs); + const [lastLog, setLastLog] = useState(null); + if (logShown && lastLog !== shown) setLastLog(shown); + const keptLog = logShown ? shown : lastLog && isLogTab(lastLog, logTabs) ? lastLog : null; + const logHost = useRef(null); + useSelectionVisibility(logHost, !!keptLog); if (!available && !external) return ( @@ -107,11 +118,18 @@ export function GitToolWindow() { ) : shown === "worktrees" ? ( - ) : ( - // Each log tab has its own view (its filters and commits are swapped into the store). - - - + ) : null} + {keptLog && ( +
+ {/* Each log tab has its own view (its filters and commits are swapped into the store). */} + + + +
)} );