diff --git a/src/features/vcs/__tests__/directoryCompareActions.test.ts b/src/features/vcs/__tests__/directoryCompareActions.test.ts index a85d3eca75..dfff1fc10e 100644 --- a/src/features/vcs/__tests__/directoryCompareActions.test.ts +++ b/src/features/vcs/__tests__/directoryCompareActions.test.ts @@ -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 } }); diff --git a/src/features/vcs/compare.tsx b/src/features/vcs/compare.tsx index c13c6e43a6..7f494b0d11 100644 --- a/src/features/vcs/compare.tsx +++ b/src/features/vcs/compare.tsx @@ -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 }); }, },