mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
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.
This commit is contained in:
@@ -19,6 +19,7 @@ export function ComparisonTree<F>({
|
||||
getColor,
|
||||
onOpen,
|
||||
inlineDiff = true,
|
||||
openDiff = (diff) => void openVcsDiff(diff),
|
||||
}: {
|
||||
tree: FileTreeNode<F>[];
|
||||
current: F | null;
|
||||
@@ -32,6 +33,8 @@ export function ComparisonTree<F>({
|
||||
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<ReadonlySet<string>>(new Set());
|
||||
const [expanded, setExpanded] = useState<ReadonlySet<string> | null>(null);
|
||||
@@ -58,7 +61,7 @@ export function ComparisonTree<F>({
|
||||
onSelect(entry);
|
||||
const diff = diffFor(entry);
|
||||
if (openOnActivate && diff) {
|
||||
void openVcsDiff(diff);
|
||||
openDiff(diff);
|
||||
onOpen?.();
|
||||
}
|
||||
}}
|
||||
|
||||
@@ -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) =>
|
||||
|
||||
@@ -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<typeof import("@/platform/actions")>()),
|
||||
executeAction,
|
||||
}));
|
||||
|
||||
vi.mock("@/platform/ipc", async (importOriginal) => {
|
||||
const real = await importOriginal<typeof import("@/platform/ipc")>();
|
||||
@@ -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(<PushChanges repo="/r" commits={[older]} onSelectFile={select} />);
|
||||
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(<PushChanges repo="/r" commits={[newer, older]} />);
|
||||
|
||||
Reference in New Issue
Block a user