fix(vcs): F7 goes on to the next file in diffs opened from a changes tree (#6052)

A diff opened from a changes tree (Compare with Local / Compare with Branch,
Changes Between, push dialog, rebase plan) was a single-file diff with no
chain, so F7 at the last difference had no next file. Opening a file from the
shared ComparisonTree and the Changes Between dialog's Show Diff now pass the
tree's files in display order as the chain (chainedDiff), like Git Log commit
details already do.

Closes #6051

Co-authored-by: formiat <[email protected]>
Цей коміт міститься в:
Alexanderтаformiat authored and GitHub committed 2026-11-26 12:50:09 +08:00
1 джерело 8d4b360933
коміт 5886e055b4
3 files changed
+37 -5

No files matched your search

+19 -2
Переглянути файл
@@ -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<F>(
tree: readonly FileTreeNode<F>[],
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<F>({
tree,
@@ -60,7 +77,7 @@ export function ComparisonTree<F>({
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?.();
+14
Переглянути файл
@@ -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(<CompareToolWindow />);
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" });
+4 -3
Переглянути файл
@@ -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();
}