From 0666f9ea5a9524d4780dc92aa1bc5d3ad0093128 Mon Sep 17 00:00:00 2001 From: solhovoy <50910307+solhovoy@users.noreply.github.com> Date: Wed, 2 Dec 2026 15:19:46 +0200 Subject: [PATCH] feat(vcs): rename shelves with F2 and keep Shelf expansion state (#7527) F2 renames the selected shelf when the Shelf list has focus. Root and group expansion in the Shelf tab survives remounts, with groups expanded by default. Co-authored-by: solhovoy <50910307+solhovoy@users.noreply.github.com> --- src/features/vcs/__tests__/shelf.test.tsx | 16 +++++++++++++-- src/features/vcs/historyActions.tsx | 4 +++- src/features/vcs/shelf.tsx | 24 +++++++++++++++++------ src/platform/keymaps/eclipse.test.ts | 5 +++-- src/platform/keymaps/intellij-macos.ts | 1 + src/platform/keymaps/intellij-windows.ts | 1 + src/platform/keymaps/vscode-macos.ts | 1 + 7 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/features/vcs/__tests__/shelf.test.tsx b/src/features/vcs/__tests__/shelf.test.tsx index 1e861a313b..54275de529 100644 --- a/src/features/vcs/__tests__/shelf.test.tsx +++ b/src/features/vcs/__tests__/shelf.test.tsx @@ -82,7 +82,7 @@ beforeEach(() => { useCommit.setState({ selectedShelf: "work\u0000a.txt" }); localStorage.removeItem("openidea.vcs.shelf.groupByDir"); localStorage.removeItem("openidea.vcs.shelf.diffPreview"); - useShelf.setState({ shelves: [entry], loaded: true, diffs: { work: diffs } }); + useShelf.setState({ shelves: [entry], loaded: true, diffs: { work: diffs }, expanded: null }); mocks.ipc.mockResolvedValueOnce([entry]).mockResolvedValue(diffs); }); afterEach(cleanup); @@ -285,10 +285,22 @@ describe("shelf scope and diffs", () => { "Delete…", ]) expect(labels.some((s) => s?.includes(label))).toBe(true); - expect(screen.getByRole("menuitem", { name: "Rename…" }).getAttribute("aria-disabled")).toBe("true"); + expect(screen.getByRole("menuitem", { name: /^Rename…/ }).getAttribute("aria-disabled")).toBe("true"); fireEvent.click(screen.getByRole("menuitem", { name: "Copy as Patch to Clipboard" })); expect(mocks.execute).toHaveBeenCalledWith("vcs.shelf.copyPatch", { id: "work", path: "a.txt" }); }); + it("starts expanded and keeps collapsed shelves when the tab is remounted", async () => { + const view = render(); + expect(await screen.findByText("a.txt")).toBeTruthy(); + fireEvent.click(screen.getByRole("button", { name: "Collapse All" })); + expect(screen.queryByText("a.txt")).toBeNull(); + view.unmount(); + mocks.ipc.mockReset().mockResolvedValueOnce([entry]).mockResolvedValue([]); + render(); + expect(await screen.findByText("Work")).toBeTruthy(); + expect(screen.queryByText("a.txt")).toBeNull(); + }); + it("deletes the selected shelf with the Delete key", async () => { useShelf.setState({ shelves: [entry] }); useCommit.setState({ selectedShelf: "work" }); diff --git a/src/features/vcs/historyActions.tsx b/src/features/vcs/historyActions.tsx index 8427da293b..a0391c44d5 100644 --- a/src/features/vcs/historyActions.tsx +++ b/src/features/vcs/historyActions.tsx @@ -689,7 +689,7 @@ export function registerHistoryActions(): () => void { title: "Edit Changelist…", category: "Git", when: VCS, - keyWhen: IN_COMMIT, + keyWhen: `${IN_COMMIT} && !shelfFocus`, run: ({ arg }) => { const id = listArg(arg) ?? useChangelists.getState().state.active; editChangelist(id); @@ -800,7 +800,9 @@ export function registerHistoryActions(): () => void { title: "Rename Shelved Changes…", category: "Git", when: VCS, + keyWhen: "vcsAvailable && shelfFocus && shelfListSelected", hidden: true, + keymap: true, run: ({ arg }) => { const target = shelfTarget(arg); if (target && !target.path) void renameShelf(target.entry); diff --git a/src/features/vcs/shelf.tsx b/src/features/vcs/shelf.tsx index 42699e9cf6..23a90fb8ca 100644 --- a/src/features/vcs/shelf.tsx +++ b/src/features/vcs/shelf.tsx @@ -93,9 +93,11 @@ interface ShelfState { shelves: ShelvedChangeList[]; loaded: boolean; diffs: Record; + /** Expanded shelf and group nodes; kept here so the tree keeps its state while the tab is not shown. */ + expanded: { root: string | null; grouping: string; keys: ReadonlySet } | null; } -export const useShelf = create(() => ({ shelves: [], loaded: false, diffs: {} })); +export const useShelf = create(() => ({ shelves: [], loaded: false, diffs: {}, expanded: null })); export async function loadShelves(): Promise { const root = useVcs.getState().root; @@ -727,7 +729,12 @@ function shelfMenu(node: ShelfNode, canCompare: boolean) { { label: "Copy as Patch to Clipboard", icon: "copy", disabled: !available, run: action("vcs.shelf.copyPatch") }, { label: "Import Patches…", run: action("vcs.shelf.importPatches") }, { kind: "separator" as const }, - { label: "Rename…", disabled: !!node.file, run: action("vcs.shelf.rename") }, + { + label: "Rename…", + shortcut: shortcutLabel("vcs.shelf.rename"), + disabled: !!node.file || !!node.directory, + run: action("vcs.shelf.rename"), + }, { label: "Delete…", icon: "trash", danger: true, disabled: !available, run: action("vcs.shelf.delete") }, ]; } @@ -850,7 +857,7 @@ export function ShelfPanel() { const nonModal = useWorkflowSettings((s) => s.vcs.commit.nonModal); const [diffPreviewOption, setDiffPreview] = useState(() => readShelfViewOption("diffPreview", true)); const diffPreview = diffPreviewOption && !nonModal; - const [expanded, setExpanded] = useState<{ scope: string; keys: ReadonlySet } | null>(null); + const expanded = useShelf((s) => s.expanded); useLayoutEffect(() => { const panel = panelRef.current; if (!panel) return; @@ -914,10 +921,15 @@ export function ShelfPanel() { [shelves, groupByDir, groupByModule, changeModules, root], ); const allKeys = useMemo(() => shelfDirKeys(nodes), [nodes]); - const expansionScope = `${groupByDir}:${groupByModule}`; - const expandedKeys = expanded?.scope === expansionScope ? expanded.keys : new Set(allKeys); - const updateExpanded = (keys: Set) => setExpanded({ scope: expansionScope, keys }); + const grouping = `${groupByDir}:${groupByModule}`; + const expandedKeys = expanded?.root === root && expanded.grouping === grouping ? expanded.keys : new Set(allKeys); + const updateExpanded = (keys: Set) => useShelf.setState({ expanded: { root, grouping, keys } }); const current = selectedShelf ? shelfTarget(selectedShelf) : null; + const listSelected = !!current && !current.path; + useEffect(() => { + setContext("shelfListSelected", listSelected); + return () => setContext("shelfListSelected", false); + }, [listSelected]); const previewDiff = diffPreview && current?.path ? shelfDiffs({ id: current.entry.id, path: current.path })[0] : null; const previewInput = previewDiff ? diffInput(previewDiff) : null; const tree = ( diff --git a/src/platform/keymaps/eclipse.test.ts b/src/platform/keymaps/eclipse.test.ts index f05854bb63..d2cb2c87e3 100644 --- a/src/platform/keymaps/eclipse.test.ts +++ b/src/platform/keymaps/eclipse.test.ts @@ -50,7 +50,7 @@ const shared = [ ["navigate.toggleBookmarkWithMnemonic", "vcs.log.toggleBookmarkWithMnemonic"], ["find.previous", "find.popup.previousResult"], ["find.usages", "project.findUsages"], - ["code.quickDocumentation", "db.quickDoc", "debug.setValue", "vcs.changelist.edit"], + ["code.quickDocumentation", "db.quickDoc", "debug.setValue", "vcs.changelist.edit", "vcs.shelf.rename"], ["code.reformat", "project.reformatCode", "db.reformatValue"], ["code.optimizeImports", "project.optimizeImports"], ["code.deleteLine", "db.duplicateSource", "project.compareWith", "vcs.showDiff", "vcs.log.changes.showDiff"], @@ -250,13 +250,14 @@ it("renames in the project view although the preset shares Alt+Shift+R with the id: "vcs.shelf.rename", title: "Rename Shelved Changes…", when: "vcsAvailable", + keyWhen: "vcsAvailable && shelfFocus && shelfListSelected", run: shelfRename, }), registerAction({ id: "vcs.changelist.edit", title: "Edit Changelist…", when: "vcsAvailable", - keyWhen: "vcsAvailable && activeToolWindow == commit", + keyWhen: "vcsAvailable && activeToolWindow == commit && !shelfFocus", run: editChangelist, }), registerAction({ id: "code.quickDocumentation", title: "Quick Documentation", when: EDITOR, run: quickDoc }), diff --git a/src/platform/keymaps/intellij-macos.ts b/src/platform/keymaps/intellij-macos.ts index 3f02b51919..923c4b43d1 100644 --- a/src/platform/keymaps/intellij-macos.ts +++ b/src/platform/keymaps/intellij-macos.ts @@ -426,6 +426,7 @@ export const intellijMacos: Record = { "vcs.shelveSilently": ["Meta+Shift+H"], "vcs.unshelveSilently": ["Meta+Alt+U"], "vcs.changelist.edit": ["F2", "Shift+F6"], + "vcs.shelf.rename": ["F2", "Shift+F6"], "vcs.log.copyRevision": ["Meta+Alt+Shift+C"], "vcs.log.maximizeCommitMessage": [], "vcs.log.copyCommitSubject": [], diff --git a/src/platform/keymaps/intellij-windows.ts b/src/platform/keymaps/intellij-windows.ts index 1db44465ea..3eb97d69af 100644 --- a/src/platform/keymaps/intellij-windows.ts +++ b/src/platform/keymaps/intellij-windows.ts @@ -424,6 +424,7 @@ export const intellijWindows: Record = { "vcs.shelveSilently": ["Ctrl+Shift+H"], "vcs.unshelveSilently": ["Ctrl+Alt+U"], "vcs.changelist.edit": ["F2", "Shift+F6"], + "vcs.shelf.rename": ["F2", "Shift+F6"], "vcs.log.copyRevision": ["Ctrl+Alt+Shift+C"], "vcs.log.maximizeCommitMessage": [], "vcs.log.copyCommitSubject": [], diff --git a/src/platform/keymaps/vscode-macos.ts b/src/platform/keymaps/vscode-macos.ts index 236f9521ac..fc9d84e62f 100644 --- a/src/platform/keymaps/vscode-macos.ts +++ b/src/platform/keymaps/vscode-macos.ts @@ -439,6 +439,7 @@ export const vscodeMacos: Record = { "vcs.shelveSilently": [], "vcs.unshelveSilently": [], "vcs.changelist.edit": [], + "vcs.shelf.rename": [], "vcs.log.copyRevision": [], "vcs.log.maximizeCommitMessage": [], "vcs.log.refresh": [],