From a0a51a63cb05eb683243d7e5bd2b428e52e1a424 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Thu, 19 Nov 2026 18:28:32 +0800 Subject: [PATCH] feat(vcs): open a push dialog file's diff in its own window (#4490) Double-click or Enter on a file in the push dialog opens its diff in a separate diff window (Show Diff in New Window), as IDEA's push dialog does; closing it returns to the dialog. Before, the diff was only shown in a split inside the small modal dialog. Selecting a file still shows the diff in the dialog. --- src/features/vcs/ComparisonTree.tsx | 5 +++- src/features/vcs/PushChanges.tsx | 8 +++++-- .../vcs/__tests__/pushChanges.test.tsx | 23 ++++++++++++++++++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/features/vcs/ComparisonTree.tsx b/src/features/vcs/ComparisonTree.tsx index 5defe247f..9aa5ecc0e 100644 --- a/src/features/vcs/ComparisonTree.tsx +++ b/src/features/vcs/ComparisonTree.tsx @@ -19,6 +19,7 @@ export function ComparisonTree({ getColor, onOpen, inlineDiff = true, + openDiff = (diff) => void openVcsDiff(diff), }: { tree: FileTreeNode[]; current: F | null; @@ -32,6 +33,8 @@ export function ComparisonTree({ onOpen?: () => void; /** Show the selected file's diff beside the tree; off where there is no room (a sidebar). */ inlineDiff?: boolean; + /** With `openOnActivate`: where a double-clicked file's diff opens (default: an editor tab). */ + openDiff?: (diff: DiffData) => void; }) { const [selected, setSelected] = useState>(new Set()); const [expanded, setExpanded] = useState | null>(null); @@ -58,7 +61,7 @@ export function ComparisonTree({ onSelect(entry); const diff = diffFor(entry); if (openOnActivate && diff) { - void openVcsDiff(diff); + openDiff(diff); onOpen?.(); } }} diff --git a/src/features/vcs/PushChanges.tsx b/src/features/vcs/PushChanges.tsx index aae1d9b78..b3e1cc481 100644 --- a/src/features/vcs/PushChanges.tsx +++ b/src/features/vcs/PushChanges.tsx @@ -1,10 +1,12 @@ /** * Push dialog: the files changed by the outgoing commits (the selected commit's, or all of - * them), with the selected file's diff beside the tree. The diff stays inside the dialog, - * which is modal. A single commit also shows its message, author and time. + * them), with the selected file's diff beside the tree. Double-click or Enter opens the diff in + * its own window, as IDEA does, since the dialog is modal and small. A single commit also shows + * its message, author and time. */ import { useEffect, useMemo, useState } from "react"; import type { ChangedFile, Commit, RevisionChange } from "@/bindings"; +import { executeAction } from "@/platform/actions"; import { call, commands } from "@/platform/ipc"; import { tx } from "@/platform/i18n"; import { Button, IconButton, Spinner, SplitGroup, SplitHandle, SplitPanel, T } from "@/ui"; @@ -94,6 +96,8 @@ export function PushChanges({ }} diffFor={(c) => c.diff} inlineDiff={!onSelectFile} + openOnActivate + openDiff={(diff) => void executeAction("vcs.showDiffInNewWindow", diff)} getColor={(c) => KIND_COLOR[c.kind === "untracked" ? "added" : c.kind]} ariaLabel="Changed files" renderDetails={(n) => diff --git a/src/features/vcs/__tests__/pushChanges.test.tsx b/src/features/vcs/__tests__/pushChanges.test.tsx index b400a332a..f32e7b25b 100644 --- a/src/features/vcs/__tests__/pushChanges.test.tsx +++ b/src/features/vcs/__tests__/pushChanges.test.tsx @@ -2,7 +2,16 @@ import { describe, expect, it, vi } from "vitest"; import { fireEvent, render, screen } from "@testing-library/react"; import type { Commit } from "@/bindings"; -const { files, combined } = vi.hoisted(() => ({ files: vi.fn(), combined: vi.fn() })); +const { files, combined, executeAction } = vi.hoisted(() => ({ + files: vi.fn(), + combined: vi.fn(), + executeAction: vi.fn(async () => true), +})); + +vi.mock("@/platform/actions", async (importOriginal) => ({ + ...(await importOriginal()), + executeAction, +})); vi.mock("@/platform/ipc", async (importOriginal) => { const real = await importOriginal(); @@ -76,6 +85,18 @@ describe("Push dialog changes", () => { expect(localStorage.getItem("openidea.vcs.push.groupByDirectory")).toBe("false"); }); + it("opens a double-clicked file's diff in its own window and keeps the selection's diff in the dialog", async () => { + files.mockResolvedValue({ status: "ok", data: [{ path: "a.txt", oldPath: null, kind: "modified" }] }); + const select = vi.fn(); + render(); + fireEvent.doubleClick(await screen.findByText("a.txt")); + expect(select).toHaveBeenLastCalledWith(expect.objectContaining({ path: "a.txt" })); + expect(executeAction).toHaveBeenCalledWith( + "vcs.showDiffInNewWindow", + expect.objectContaining({ path: expect.stringContaining("a.txt") }), + ); + }); + it("shows no commit details for several commits", async () => { combined.mockResolvedValue({ status: "ok", data: [] }); render();