diff --git a/src/features/vcs/ComparisonTree.tsx b/src/features/vcs/ComparisonTree.tsx index 0be6d1a2c1..c950a1954c 100644 --- a/src/features/vcs/ComparisonTree.tsx +++ b/src/features/vcs/ComparisonTree.tsx @@ -1,12 +1,29 @@ import { useState, type ReactNode } from "react"; import { Icon, Tree, fileIconName, lazyComponent } from "@/ui"; -import { diffInput, openVcsDiff, type DiffData } from "./diffInput"; +import { diffInput, openVcsDiff, withChain, type DiffData } from "./diffInput"; import { dirKeys, type FileTreeNode } from "./fileTree"; +import { filesUnder } from "./logChanges"; import styles from "./common.module.css"; const DiffEditor = lazyComponent(() => import("./DiffEditor").then((m) => m.DiffEditor)); const defaultOpenDiff = (diff: DiffData) => void openVcsDiff(diff); +/** `file`'s diff with the tree's other files as its chain, in display order: F7 goes on to the next file (IDEA). */ +export function chainedDiff( + tree: readonly FileTreeNode[], + file: F, + diffFor: (entry: F) => DiffData | null, +): DiffData | null { + const files = filesUnder(tree).filter((f) => diffFor(f)); + const index = files.indexOf(file); + return index < 0 + ? diffFor(file) + : withChain( + files.map((f) => diffFor(f)!), + index, + ); +} + /** Shared changes tree and on-demand diff surface for revisions and disk folders. */ export function ComparisonTree({ tree, @@ -60,7 +77,7 @@ export function ComparisonTree({ const entry = n.file ?? n.directory; if (!entry) return; onSelect(entry); - const diff = diffFor(entry); + const diff = n.file ? chainedDiff(tree, n.file, diffFor) : diffFor(entry); if (openOnActivate && diff) { openDiff(diff); onOpen?.(); diff --git a/src/features/vcs/__tests__/compareTool.test.tsx b/src/features/vcs/__tests__/compareTool.test.tsx index a878148b19..6d3e121800 100644 --- a/src/features/vcs/__tests__/compareTool.test.tsx +++ b/src/features/vcs/__tests__/compareTool.test.tsx @@ -39,6 +39,7 @@ vi.mock("@/workbench/contributions", async (original) => { import { useProject } from "@/platform/project"; import { ChangesBetweenDialog, comparisonDiffData, type ComparisonFile } from "../operations"; import { CompareToolWindow, useCompareTool } from "../compareTool"; +import type { DiffData } from "../diffInput"; import { useVcs } from "../store"; const modified: ComparisonFile = { @@ -126,6 +127,19 @@ describe("CompareToolWindow", () => { expect(mocks.openFile).toHaveBeenCalledWith("/workspace/client/src/app.ts", { focus: true }); }); + it("opens a file's diff with the listed files as its chain, so F7 goes on to the next file (IDEA)", async () => { + mocks.openDiff.mockResolvedValue(undefined); + render(); + fireEvent.doubleClick(await screen.findByText("new.ts")); + const data = mocks.openDiff.mock.calls[0]![0] as DiffData; + expect(data.path).toBe("/workspace/client/src/new.ts"); + expect(data.chain?.map((d) => d.path)).toEqual([ + "/workspace/client/src/app.ts", + "/workspace/client/src/new.ts", + "/workspace/client/src/old.ts", + ]); + }); + it("groups working-tree diffs by the requested repositories and opens the selected copy of a common path", async () => { const roots = ["/workspace/client", "/workspace/server"]; useVcs.setState({ roots: [...roots, "/workspace/tools"], repo: "/workspace/tools" }); diff --git a/src/features/vcs/operations.tsx b/src/features/vcs/operations.tsx index 6860b7afc7..3ab83ba43e 100644 --- a/src/features/vcs/operations.tsx +++ b/src/features/vcs/operations.tsx @@ -58,7 +58,7 @@ import { import styles from "./common.module.css"; import resetStyles from "./ResetDialog.module.css"; import tagStyles from "./TagDialog.module.css"; -import { ComparisonTree } from "./ComparisonTree"; +import { ComparisonTree, chainedDiff } from "./ComparisonTree"; import { showWorktreeComparison } from "./compareTool"; import { buildFileTree, type FileTreeNode } from "./fileTree"; import { tx, txPart } from "@/platform/i18n"; @@ -1277,9 +1277,10 @@ export function ChangesBetweenDialog({ }, [native, onCaption, caption]); const showDiff = () => { if (!current) return; - if (onShowDiff) onShowDiff(diffFor(current)); + const data = chainedDiff(tree, current, diffFor) ?? diffFor(current); + if (onShowDiff) onShowDiff(data); else { - void openVcsDiff(diffFor(current)); + void openVcsDiff(data); // A diff window opens on top of this list (#1863); an editor tab would sit behind it. if (!vcsDiffInFront()) onClose(); }