fix(vcs): open Show Diff on multi-file selections as one diff chain (#7870)

Show Diff on the Changes changelist node, or on several changed files, opened the Changes between HEAD and Local Working Tree comparison window, because only single-file selections reached the file diff. A selection made only of changed files now opens one diff tab whose files form the F7 chain, as the modal commit interface already did; directories and changed submodule entries keep the comparison window.

Closes #7865

Co-authored-by: koeria <[email protected]>
Цей коміт міститься в:
koeriaтаkoeria authored and GitHub committed 2026-12-04 03:52:28 +08:00
1 джерело ac9198dd52
коміт 309a805794
4 files changed
+43

No files matched your search

+18
Переглянути файл
@@ -1,4 +1,5 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import type { FileStatus } from "@/bindings";
const mocks = vi.hoisted(() => ({
scope: vi.fn(),
@@ -93,4 +94,21 @@ describe("comparison flow", () => {
expect(await showDirectoryWorkingDiff([path])).toBe(false);
expect(mocks.show).not.toHaveBeenCalled();
});
it("opens changed files as the file diff chain instead of a comparison window", async () => {
const files = ["/server/a.ts", "/server/b.ts"].map((path) => ({
path,
relPath: path.slice("/server/".length),
unstaged: "modified",
staged: null,
renamedFrom: null,
})) as FileStatus[];
useVcs.setState({ status: files, byPath: new Map(files.map((f) => [f.path, f])) });
mocks.scope.mockResolvedValue({
status: "ok",
data: { repositories: ["/server"], singleFile: false, skippedPaths: [] },
});
expect(await showDirectoryWorkingDiff(["/server/a.ts", "/server/b.ts"])).toBe(false);
expect(mocks.show).not.toHaveBeenCalled();
});
});
+10
Переглянути файл
@@ -169,6 +169,16 @@ it("keeps the front diff dialog when the diff window cannot open", async () => {
expect(closeOpenDiffDialog).not.toHaveBeenCalled();
});
it("opens a changelist-node selection of several changed files as one diff chain", async () => {
setContext("activeToolWindow", "commit");
useCommit.setState({ selection: ["/repo/a.ts", "/repo/b.ts", "/repo/z.ts"] });
await getAction("vcs.showDiff")!.run({ arg: undefined, ctx: { vcsAvailable: true } });
expect(opened).toHaveBeenCalledTimes(1);
const data = opened.mock.calls[0]![0].data;
expect(data.path).toBe("/repo/a.ts");
expect(data.chain.map((d: { path: string }) => d.path)).toEqual(["/repo/a.ts", "/repo/b.ts", "/repo/z.ts"]);
});
it("opens the front diff window from the modal Local Changes selection (⌘D)", async () => {
modal();
setContext("activeToolWindow", "git");
+12
Переглянути файл
@@ -936,6 +936,18 @@ export function registerVcsActions(): () => void {
await openVcsDiff({ ...data, line });
return;
}
// Several selected changed files (a changelist node) open as one diff chain,
// as the modal interface does; a path that the tree lists once keeps its group.
if (targets.length > 1 && targets.every((t) => typeof t !== "string")) {
await openVcsDiff({
...withChain(
targets.map((t) => changeNodeDiff(t)),
0,
),
line,
});
return;
}
for (const target of targets.slice(0, 5)) {
const data = typeof target === "string" ? groupDiffData(tree, target) : changeNodeDiffData(tree, target);
// oxlint-disable-next-line no-await-in-loop -- diff tabs open in selection order
+3
Переглянути файл
@@ -46,6 +46,9 @@ export async function showDirectoryWorkingDiff(paths: string[]): Promise<boolean
if (paths.length && paths.every((path) => statusOf(path))) {
const entries = await loadDiffEntries(paths.flatMap((path) => ["WT", ":0", "HEAD"].map((rev) => ({ path, rev }))));
if (entries?.some((entry) => entry?.mode === GITLINK_MODE)) return false;
// A selection of changed files (a changelist node, several file rows) opens the
// file diff chain, like a single file does; the comparison stays for directories.
return false;
}
if (!scope.repositories.length) {
notifications().notify({