дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 18:17:15 +02:00
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 <[email protected]>
Цей коміт міститься в:
1 джерело
3fe4e12252
коміт
0666f9ea5a
7 files changed
+41
-11
No files matched your search
@@ -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(<ShelfPanel />);
|
||||
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(<ShelfPanel />);
|
||||
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" });
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -93,9 +93,11 @@ interface ShelfState {
|
||||
shelves: ShelvedChangeList[];
|
||||
loaded: boolean;
|
||||
diffs: Record<string, ShelfDiffFile[]>;
|
||||
/** 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<string> } | null;
|
||||
}
|
||||
|
||||
export const useShelf = create<ShelfState>(() => ({ shelves: [], loaded: false, diffs: {} }));
|
||||
export const useShelf = create<ShelfState>(() => ({ shelves: [], loaded: false, diffs: {}, expanded: null }));
|
||||
|
||||
export async function loadShelves(): Promise<ShelvedChangeList[]> {
|
||||
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<string> } | 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<string>) => 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<string>) => 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 = (
|
||||
|
||||
@@ -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 }),
|
||||
|
||||
@@ -426,6 +426,7 @@ export const intellijMacos: Record<string, string[]> = {
|
||||
"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": [],
|
||||
|
||||
@@ -424,6 +424,7 @@ export const intellijWindows: Record<string, string[]> = {
|
||||
"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": [],
|
||||
|
||||
@@ -439,6 +439,7 @@ export const vscodeMacos: Record<string, string[]> = {
|
||||
"vcs.shelveSilently": [],
|
||||
"vcs.unshelveSilently": [],
|
||||
"vcs.changelist.edit": [],
|
||||
"vcs.shelf.rename": [],
|
||||
"vcs.log.copyRevision": [],
|
||||
"vcs.log.maximizeCommitMessage": [],
|
||||
"vcs.log.refresh": [],
|
||||
|
||||
Reference in new issue
Заблокувати користувача