diff --git a/e2e/gitLogToolbarMenus.spec.ts b/e2e/gitLogToolbarMenus.spec.ts index da46c3c430..292e173a5c 100644 --- a/e2e/gitLogToolbarMenus.spec.ts +++ b/e2e/gitLogToolbarMenus.spec.ts @@ -523,17 +523,16 @@ test("Git Log file selection stays in place and opens a diff on activation", asy await expect(firstDiff).toHaveAttribute("aria-selected", "true"); }); -test("a Git Log file's diff window under the modal commit interface takes focus: F7 works at once", async ({ - workbench: page, -}) => { +test("a Git Log file's diff opens in the diff window under the modal commit interface", async ({ workbench: page }) => { await page.evaluate(async () => { const h = window.__ipc.handlers; h.vcs_commit_files = () => [{ path: "src/orders.ts", kind: "modified", oldPath: null }]; - // Two differences far apart, so F7 has somewhere to go. - h.vcs_file_at = ({ rev }) => { - const lines = Array.from({ length: 80 }, (_, i) => `const step${i} = ${i};`); - if (rev === "0".repeat(40)) for (const i of [5, 60]) lines[i] = `const step${i} = ${i} * 2;`; - return `${lines.join("\n")}\n`; + h.vcs_file_at = () => "const step = 1;\n"; + const w = window as unknown as { diffLaunches: unknown[] }; + w.diffLaunches = []; + h.window_open_diff = ({ diff }) => { + w.diffLaunches.push(diff); + return null; }; const projectModule = "/src/platform/project.ts"; const { useProject } = await import(/* @vite-ignore */ projectModule); @@ -543,12 +542,10 @@ test("a Git Log file's diff window under the modal commit interface takes focus: }); await page.getByRole("listbox", { name: "Commits" }).getByRole("option").first().click(); await page.getByRole("tree", { name: "Changed files" }).getByRole("treeitem", { name: "orders.ts" }).dblclick(); - const dialog = page.getByRole("dialog", { name: /^orders\.ts/ }); - await expect(dialog.getByText("1 of 2 differences", { exact: true })).toBeVisible(); - // The diff's text has focus, not the toolbar's first button. - await expect(dialog.locator(".cm-editor.cm-focused")).toHaveCount(1); - await page.keyboard.press("F7"); - await expect(dialog.getByText("2 of 2 differences", { exact: true })).toBeVisible(); + await expect + .poll(() => page.evaluate(() => (window as unknown as { diffLaunches: { path: string }[] }).diffLaunches)) + .toEqual([expect.objectContaining({ path: expect.stringMatching(/orders\.ts$/) })]); + await expect(page.getByRole("dialog", { name: /^orders\.ts/ })).toHaveCount(0); }); test("Not Cherry-Picked Commits dims other rows while keeping unpicked commits readable", async ({ diff --git a/src/features/vcs/__tests__/modalDiffWindow.test.ts b/src/features/vcs/__tests__/modalDiffWindow.test.ts index 127ecf16ee..e93da630bd 100644 --- a/src/features/vcs/__tests__/modalDiffWindow.test.ts +++ b/src/features/vcs/__tests__/modalDiffWindow.test.ts @@ -10,6 +10,8 @@ const front = vi.hoisted(() => ({ diff: vi.fn(), merge: vi.fn() })); vi.mock("../diffDialog", () => ({ openDiffDialog: front.diff, openMergeDiffDialog: front.merge })); const separate = vi.hoisted(() => vi.fn()); vi.mock("../DiffWindow", () => ({ showDiffWindow: separate })); +// The desktop shell: the modal interface's diffs go to the diff window there. +vi.mock("@/platform/ipc", async (orig) => ({ ...(await orig()), isTauri: () => true })); /** Editor tabs the diffs open in (openDiff → the editor service). */ const openInput = vi.fn(async () => undefined); @@ -21,7 +23,12 @@ const modal = (on: boolean) => let unregister: () => void; beforeAll(() => (unregister = registerCompareActions())); afterAll(() => unregister()); -beforeEach(() => modal(false)); +beforeEach(() => { + modal(false); + front.diff.mockClear(); + separate.mockReset(); + openInput.mockClear(); +}); const texts = { path: "/p/a.ts", left: { text: "a", label: "Expected" }, right: { text: "b", label: "Actual" } }; const merge = { @@ -40,8 +47,18 @@ const merge = { diff: { path: "/p/a.ts", left: { type: "rev", rev: "p1" }, right: { type: "rev", rev: "m" } }, } as LogChange; -it("opens Compare actions in the front window under the modal interface", async () => { +it("opens Compare actions in the diff window under the modal interface", async () => { modal(true); + separate.mockResolvedValueOnce(true); + await getAction("diff.compareTexts")!.run({ arg: texts, ctx: {} }); + expect(separate).toHaveBeenCalledWith(expect.objectContaining({ path: "/p/a.ts" }), expect.any(Function)); + expect(front.diff).not.toHaveBeenCalled(); + expect(openInput).not.toHaveBeenCalled(); +}); + +it("falls back to the front diff dialog when the diff window can't open", async () => { + modal(true); + separate.mockResolvedValueOnce(false); await getAction("diff.compareTexts")!.run({ arg: texts, ctx: {} }); expect(front.diff).toHaveBeenCalledWith(expect.objectContaining({ path: "/p/a.ts" })); expect(openInput).not.toHaveBeenCalled(); @@ -83,9 +100,10 @@ it("opens diffs in a separate window when Open diff as editor tab is off", async await getAction("diff.compareTexts")!.run({ arg: texts, ctx: {} }); expect(separate).toHaveBeenCalledWith(expect.objectContaining({ path: "/p/a.ts" }), expect.any(Function)); expect(openInput).not.toHaveBeenCalled(); - // The modal commit interface still shows them in its front window. + // The modal commit interface uses the diff window too. useProject.setState({ settings: { vcs: { diffAsEditorTab: false, commit: { nonModal: false } } } as Settings }); + separate.mockResolvedValueOnce(true); await getAction("diff.compareTexts")!.run({ arg: texts, ctx: {} }); - expect(front.diff).toHaveBeenCalledTimes(1); - expect(separate).toHaveBeenCalledTimes(1); + expect(separate).toHaveBeenCalledTimes(2); + expect(front.diff).not.toHaveBeenCalled(); }); diff --git a/src/features/vcs/diffInput.ts b/src/features/vcs/diffInput.ts index 8a2844825f..8a8e0ee570 100644 --- a/src/features/vcs/diffInput.ts +++ b/src/features/vcs/diffInput.ts @@ -2,7 +2,7 @@ import type { ChangedFile, FileStatus, RevisionChange } from "@/bindings"; import { COMBINED_DIFF_KIND, combinedOf, type CombinedDiffData } from "./allInOneDiff"; import { auxiliaryWindow } from "@/platform/auxWindow"; -import { call, commands, type LineEnding } from "@/platform/ipc"; +import { call, commands, isTauri, type LineEnding } from "@/platform/ipc"; import { tx } from "@/platform/i18n"; import { workflowSettings } from "@/platform/workflowSettings"; import { editorService, type EditorInput } from "@/workbench/contributions"; @@ -236,10 +236,12 @@ export const opensDiffOnActivate = () => { /** * Diffs the user opens (changed files, a log entry's file, Show Diff, Shelf, compare - * with a revision, Compare actions): the modal commit interface shows them in the front - * window (#1863), the non-modal one keeps editor tabs. Passive previews, diffs embedded - * in dedicated surfaces (the comparison window, merge editors) and pull request files - * (`vcs.openDiff`, with review comments) call openDiff directly. + * with a revision, Compare actions). The non-modal commit interface keeps editor tabs or + * the diff window (Settings › Version Control › Confirmation). The modal one shows them in + * front of the IDE and its Commit dialog (#1863): in the diff window, as IDEA does, or in a + * diff dialog when the window can't show the diff (a combined diff, no desktop shell). + * Passive previews, diffs embedded in dedicated surfaces (the comparison window, merge + * editors) and pull request files (`vcs.openDiff`, with review comments) call openDiff directly. */ export async function openVcsDiff(data: DiffData, opts: { preview?: boolean; focus?: boolean } = {}) { if (!vcsDiffInFront()) { @@ -250,7 +252,12 @@ export async function openVcsDiff(data: DiffData, opts: { preview?: boolean; foc return; } const { openDiffDialog } = await import("./diffDialog"); - openDiffDialog(data); + if (combinedOf(data) || !isTauri()) { + openDiffDialog(data); + return; + } + const { showDiffWindow } = await import("./DiffWindow"); + if (!(await showDiffWindow(data, () => void openDiffDialog(data)))) openDiffDialog(data); } /** A changes-tree file's working diff, on its side of the index under a "by staging state" group. */