From 1c00a1125d2f10abb0bd87a9ada0306b3969f495 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Sat, 14 Nov 2026 23:41:17 +0800 Subject: [PATCH] fix(ui): remember splitter positions in the Git and other tool windows SplitGroup only remembers sizes with a storageKey, and none of the Git views passed one, so the Commit, Local Changes, Log, Stash/Shelf and revision splitters went back to their defaults whenever the view was recreated. Give them, the Commit dialog, and the Todo, Find, Problems, Usages, Build, HTTP Client and Dependency Analyzer splits a key, with stable panel ids. A view whose preview pane comes and goes keys its sizes per panel set; SplitGroup now applies that set's saved sizes when the key changes, once the panels have registered, so toggling a preview restores its size without remounting the view. --- .../build-tools/DependencyAnalyzer.tsx | 6 +- src/features/build/BuildView.tsx | 7 +- src/features/code-insight/ProblemsView.tsx | 2 +- src/features/code-insight/UsagesView.tsx | 2 +- src/features/http-client/HttpClientView.tsx | 2 +- src/features/search/find/FindToolWindow.tsx | 7 +- src/features/todo/TodoView.tsx | 6 +- src/features/vcs/CommitDialog.tsx | 16 ++-- src/features/vcs/CommitView.tsx | 34 +++++--- src/features/vcs/GitLog.tsx | 4 +- src/features/vcs/RevisionBrowser.tsx | 2 +- src/ui/Splitter.test.tsx | 43 ++++++++++ src/ui/Splitter.tsx | 80 +++++++++++++++---- 13 files changed, 169 insertions(+), 42 deletions(-) create mode 100644 src/ui/Splitter.test.tsx diff --git a/src/features/build-tools/DependencyAnalyzer.tsx b/src/features/build-tools/DependencyAnalyzer.tsx index 2b48e5bf90..257393af03 100644 --- a/src/features/build-tools/DependencyAnalyzer.tsx +++ b/src/features/build-tools/DependencyAnalyzer.tsx @@ -440,7 +440,11 @@ export function DependencyAnalyzer(_props: { input: EditorInput }) { const treeView = (
- + aria-label="Dependencies" diff --git a/src/features/build/BuildView.tsx b/src/features/build/BuildView.tsx index 905dbce520..81a9d357d8 100644 --- a/src/features/build/BuildView.tsx +++ b/src/features/build/BuildView.tsx @@ -339,7 +339,12 @@ export function BuildView() { } return (
- + diff --git a/src/features/code-insight/ProblemsView.tsx b/src/features/code-insight/ProblemsView.tsx index e1c66a9ad5..3694494755 100644 --- a/src/features/code-insight/ProblemsView.tsx +++ b/src/features/code-insight/ProblemsView.tsx @@ -410,7 +410,7 @@ export function ProblemsView() {
{options.preview ? ( - + {list} diff --git a/src/features/code-insight/UsagesView.tsx b/src/features/code-insight/UsagesView.tsx index a8fb62736f..d0c1942c05 100644 --- a/src/features/code-insight/UsagesView.tsx +++ b/src/features/code-insight/UsagesView.tsx @@ -401,7 +401,7 @@ function UsagesSplit({ preview, children }: { preview: ReactNode; children: Reac const show = useUsagesOptions((s) => s.preview); if (!show) return children; return ( - + {children} diff --git a/src/features/http-client/HttpClientView.tsx b/src/features/http-client/HttpClientView.tsx index c32e061b87..bd3d6e1dca 100644 --- a/src/features/http-client/HttpClientView.tsx +++ b/src/features/http-client/HttpClientView.tsx @@ -261,7 +261,7 @@ export function HttpClientView() { void refreshHistory(); }, []); return ( - +
{running && ( diff --git a/src/features/search/find/FindToolWindow.tsx b/src/features/search/find/FindToolWindow.tsx index ab44db78f0..3ab7111d0e 100644 --- a/src/features/search/find/FindToolWindow.tsx +++ b/src/features/search/find/FindToolWindow.tsx @@ -422,7 +422,12 @@ function FindTabView({ tab }: { tab: FindTab }) { )}
- + className={styles.tree} diff --git a/src/features/todo/TodoView.tsx b/src/features/todo/TodoView.tsx index 0dbc87f376..aec895a0a6 100644 --- a/src/features/todo/TodoView.tsx +++ b/src/features/todo/TodoView.tsx @@ -478,7 +478,11 @@ export function TodoView() { {tab === "scope" && } {tab === "changes" && }
- + handleRef={tree} diff --git a/src/features/vcs/CommitDialog.tsx b/src/features/vcs/CommitDialog.tsx index 6d6581cd2c..69c9f208a7 100644 --- a/src/features/vcs/CommitDialog.tsx +++ b/src/features/vcs/CommitDialog.tsx @@ -69,14 +69,18 @@ function CommitDialog({ onClose }: { onClose: () => void }) { ]} >
- - - - + + + + - +
@@ -84,7 +88,7 @@ function CommitDialog({ onClose }: { onClose: () => void }) {
- +
diff --git a/src/features/vcs/CommitView.tsx b/src/features/vcs/CommitView.tsx index 94e9750b56..857d5282fa 100644 --- a/src/features/vcs/CommitView.tsx +++ b/src/features/vcs/CommitView.tsx @@ -184,12 +184,12 @@ export function StashContent({ tab }: { tab: CommitTab }) { const combine = useWorkflowSettings((s) => s.vcs.git.combineStashAndShelf); if (combine) return ( - - + + - + @@ -486,14 +486,18 @@ function ChangesPanel() { const path = useCommit((s) => (s.selection.length === 1 ? s.selection[0] : null)); const hasChanges = useVcs((s) => s.status.length > 0); return ( - - - - + + + + - + @@ -501,7 +505,7 @@ function ChangesPanel() { {preview && ( <> - + {path ? ( ) : ( @@ -525,14 +529,20 @@ export function LocalChangesView() { const path = useCommit((s) => (s.selection.length === 1 ? s.selection[0] : null)); const anchor = useToolWindowLayout((s) => s.placements.git?.anchor ?? "bottom"); return ( - - + + {preview && ( <> - + {path ? ( ) : ( diff --git a/src/features/vcs/GitLog.tsx b/src/features/vcs/GitLog.tsx index fe09173427..33f0c1dcb3 100644 --- a/src/features/vcs/GitLog.tsx +++ b/src/features/vcs/GitLog.tsx @@ -327,6 +327,7 @@ export function LogView() { key={showBranches ? "branches" : "no-branches"} orientation="horizontal" id={showBranches ? "git-log" : "git-log-no-branches"} + storageKey={`openidea.vcs.logSplit.${showBranches ? "branches" : "noBranches"}.${showDetails ? "details" : "noDetails"}`} className={styles.split} > {showBranches && ( @@ -2681,7 +2682,7 @@ export function CommitDetails({ commits }: { commits: Commit[] }) { }; const details = ( - +
{details} diff --git a/src/features/vcs/RevisionBrowser.tsx b/src/features/vcs/RevisionBrowser.tsx index ba1b07032b..2df54191b6 100644 --- a/src/features/vcs/RevisionBrowser.tsx +++ b/src/features/vcs/RevisionBrowser.tsx @@ -146,7 +146,7 @@ function RevisionBrowser({ ) : !files ? ( ) : ( - + localStorage.clear()); + +function Split({ storageKey, preview }: { storageKey: string; preview: boolean }) { + return ( + + + {preview && ( + <> + + + + )} + + ); +} +const ref = createRef(); + +it("starts from the sizes saved under its key", () => { + localStorage.setItem("split.preview", JSON.stringify({ tree: 30, preview: 70 })); + render(); + expect(ref.current!.getLayout()).toEqual({ tree: 30, preview: 70 }); +}); + +it("applies the saved sizes of a panel set that appears later", () => { + localStorage.setItem("split.preview", JSON.stringify({ tree: 25, preview: 75 })); + const view = render(); + view.rerender(); + expect(ref.current!.getLayout()).toEqual({ tree: 25, preview: 75 }); +}); + +it("ignores saved sizes for other panels", () => { + localStorage.setItem("split.preview", JSON.stringify({ other: 25, preview: 75 })); + const view = render(); + view.rerender(); + expect(Object.keys(ref.current!.getLayout()).sort()).toEqual(["preview", "tree"]); + expect(ref.current!.getLayout().tree).not.toBe(25); +}); diff --git a/src/ui/Splitter.tsx b/src/ui/Splitter.tsx index d4448641f7..e586d92416 100644 --- a/src/ui/Splitter.tsx +++ b/src/ui/Splitter.tsx @@ -2,36 +2,84 @@ * Thin wrappers over react-resizable-panels with IDE styling: 1px hairline * separators with a wider invisible hit area and an accent hover state. */ -import { Group, Panel, Separator, type GroupProps, type PanelProps, type SeparatorProps } from "react-resizable-panels"; +import { + Group, + Panel, + Separator, + type GroupImperativeHandle, + type GroupProps, + type PanelProps, + type SeparatorProps, +} from "react-resizable-panels"; import clsx from "clsx"; -import { useState } from "react"; +import { useEffect, useImperativeHandle, useRef, useState } from "react"; import styles from "./Splitter.module.css"; +function savedLayout(storageKey: string | undefined): Record | undefined { + try { + const value: unknown = storageKey ? JSON.parse(localStorage.getItem(storageKey) ?? "null") : null; + return value && + typeof value === "object" && + !Array.isArray(value) && + Object.values(value).every((n) => typeof n === "number" && Number.isFinite(n) && n >= 0 && n <= 100) + ? (value as Record) + : undefined; + } catch { + return undefined; + } +} + +/** + * `storageKey` remembers the sizes the user drags to. A group whose panels come and go (a + * preview pane) passes a key per panel set; when it changes, that set's sizes are applied. + */ export function SplitGroup({ className, storageKey, defaultLayout, onLayoutChanged, + groupRef, ...rest }: GroupProps & { storageKey?: string }) { - const [saved] = useState(() => { - try { - const value: unknown = storageKey ? JSON.parse(localStorage.getItem(storageKey) ?? "null") : null; - return value && - typeof value === "object" && - !Array.isArray(value) && - Object.values(value).every((n) => typeof n === "number" && Number.isFinite(n) && n >= 0 && n <= 100) - ? (value as Record) - : undefined; - } catch { - return undefined; - } - }); + const [saved] = useState(() => savedLayout(storageKey)); + const group = useRef(null); + const mountedKey = useRef(storageKey); + // Sizes to apply once the group's panels match them (a panel added with the new key registers later). + const pending = useRef | null>(null); + const applyPending = (current: Record) => { + const layout = pending.current; + if (!layout) return; + const ids = Object.keys(current); + if (ids.length !== Object.keys(layout).length || !ids.every((id) => id in layout)) return; + pending.current = null; + group.current?.setLayout(layout); + }; + useEffect(() => { + if (storageKey === mountedKey.current) return; + mountedKey.current = storageKey; + pending.current = savedLayout(storageKey) ?? null; + const current = group.current?.getLayout(); + if (current) applyPending(current); + }, [storageKey]); + useImperativeHandle( + groupRef, + () => ({ + getLayout: () => group.current?.getLayout() ?? {}, + setLayout: (layout) => group.current?.setLayout(layout) ?? layout, + }), + [], + ); + const onLayoutChange: GroupProps["onLayoutChange"] = (layout) => { + applyPending(layout); + rest.onLayoutChange?.(layout); + }; if (!storageKey) return ( @@ -40,6 +88,8 @@ export function SplitGroup({ { if (storageKey && meta.isUserInteraction) {