fix(diff): compare the Project view's two selected files when Compare Files runs from Find Action (#8287)

Run from Find Action, Compare Files got no argument and asked to select two files even with two selected. It now falls back to the Project view's selection like Compare Directories and rejects a selected directory.
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-12-06 04:11:37 +08:00
1 джерело f8e1705dff
коміт 69fca0aaa3
2 files changed
+25 -2

No files matched your search

+22
Переглянути файл
@@ -60,6 +60,28 @@ describe("directory compare actions", () => {
expect(mocks.notify).toHaveBeenCalledWith(expect.objectContaining({ title: "Select two directories to compare" }));
});
it("compares the two files selected in the Project view from Find Action", async () => {
const unselect = provideProjectViewSelection(() => ["/p/a.txt", "/p/b.txt"]);
try {
await getAction("diff.compareFiles")!.run({ ctx: { projectOpen: true } });
expect(mocks.openDiff).toHaveBeenCalledWith(expect.objectContaining({ path: "/p/b.txt" }));
expect(mocks.notify).not.toHaveBeenCalled();
} finally {
unselect();
}
});
it("does not compare a selected directory as a file", async () => {
const unselect = provideProjectViewSelection(() => ["/p/left", "/p/b.txt"]);
try {
await getAction("diff.compareFiles")!.run({ ctx: { projectOpen: true } });
expect(mocks.openDiff).not.toHaveBeenCalled();
expect(mocks.notify).toHaveBeenCalledWith(expect.objectContaining({ title: "Select two files to compare" }));
} finally {
unselect();
}
});
it("uses the native folder picker for Compare With on a local directory", async () => {
mocks.pick.mockResolvedValue("/p/right");
await getAction("diff.compareWith")!.run({ ctx: {}, arg: { path: "/p/left", directory: true } });
+3 -2
Переглянути файл
@@ -361,8 +361,9 @@ export function registerCompareActions(): () => void {
icon: "diff",
when: "projectOpen",
run: async ({ arg }) => {
const paths = argPaths(arg).filter((p) => !p.endsWith("/"));
if (paths.length !== 2) return info("Select two files to compare");
const paths = (arg === undefined ? projectViewSelection() : argPaths(arg)).filter((p) => !p.endsWith("/"));
if (paths.length !== 2 || (await isDirectory(paths[0]!)) || (await isDirectory(paths[1]!)))
return info("Select two files to compare");
await openVcsDiff({ ...compareFilesData(paths[0]!, paths[1]!), swappable: true });
},
},