From 6fbbab6c6f6d2afe9f2d0b2068886bfa3e4969fa Mon Sep 17 00:00:00 2001 From: LU XIANGRUI <1078666705@qq.com> Date: Fri, 4 Dec 2026 03:00:01 +0900 Subject: [PATCH] fix(vcs): show the file's diff to the right of file history (#7744) Fixes #6406 Git > Show History for a file now keeps the revisions and their commit details on the left (details below the revisions) and shows the selected revision's diff of that file on the right. Directory history keeps the repository log layout. The diff follows Show Diff Preview and file history's own Diff Preview Location (Right by default; Bottom puts it below; Editor leaves it out and Show Diff opens a tab). The split is remembered per location. The details pane's change loading and preview are shared with the new pane, and the rename-aware matching of the history file's changes moved to historyFileChanges so Show Diff and the pane agree. Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com> --- e2e/gitFileHistoryLayout.spec.ts | 8 +- src/features/vcs/GitLog.tsx | 66 ++++-- .../vcs/__tests__/fileHistoryLayout.test.tsx | 215 ++++++++++++++++++ src/features/vcs/log/CommitDetails.tsx | 170 +++++++------- .../vcs/log/FileHistoryDiffPreview.tsx | 57 +++++ src/features/vcs/logChanges.ts | 18 ++ src/features/vcs/logOptions.ts | 15 +- src/features/vcs/logPaneActions.ts | 14 +- 8 files changed, 450 insertions(+), 113 deletions(-) create mode 100644 src/features/vcs/__tests__/fileHistoryLayout.test.tsx create mode 100644 src/features/vcs/log/FileHistoryDiffPreview.tsx diff --git a/e2e/gitFileHistoryLayout.spec.ts b/e2e/gitFileHistoryLayout.spec.ts index 55e8c9b96f..c8d3d0e65c 100644 --- a/e2e/gitFileHistoryLayout.spec.ts +++ b/e2e/gitFileHistoryLayout.spec.ts @@ -1,6 +1,6 @@ import { expect, stubDesktop, test } from "./fixtures"; -test("file history puts commit details below the revisions and keeps directory history in the log layout", async ({ +test("file history puts commit details below the revisions, the file's diff to the right, and keeps directory history in the log layout", async ({ workbench: page, }) => { await page.setViewportSize({ width: 1100, height: 760 }); @@ -59,6 +59,11 @@ test("file history puts commit details below the revisions and keeps directory h const newest = revisions.getByRole("option", { name: /Update the reviewed totals/ }); await expect(newest).toBeVisible(); await expect(separator).toHaveAttribute("aria-orientation", "horizontal"); + // IDEA's file history: the file's diff to the right of the revisions and their details. + const diffSeparator = page.getByRole("separator", { name: "Diff", exact: true }); + await expect(diffSeparator).toHaveAttribute("aria-orientation", "vertical"); + const diffEdge = (await diffSeparator.boundingBox())!.x; + expect((await revisions.boundingBox())!.x + (await revisions.boundingBox())!.width).toBeLessThanOrEqual(diffEdge + 1); await expect(page.getByRole("toolbar", { name: "Branches", exact: true })).toHaveCount(0); await expect(page.getByRole("button", { name: "Show Branches", exact: true })).toHaveCount(0); @@ -87,6 +92,7 @@ test("file history puts commit details below the revisions and keeps directory h await expect(git.getByRole("tab", { name: /History: src/ })).toHaveAttribute("aria-selected", "true"); await expect(page.getByRole("toolbar", { name: "Branches", exact: true })).toBeVisible(); await expect(separator).toHaveCount(0); + await expect(diffSeparator).toHaveCount(0); await historyTab.click(); await expect(earlier).toHaveAttribute("aria-selected", "true"); diff --git a/src/features/vcs/GitLog.tsx b/src/features/vcs/GitLog.tsx index 59eac7d554..bb9f4a720e 100644 --- a/src/features/vcs/GitLog.tsx +++ b/src/features/vcs/GitLog.tsx @@ -23,8 +23,9 @@ import styles from "./GitLog.module.css"; import { WorktreesPanel } from "./WorktreesPanel"; import { gitTabs, shownTab } from "./gitTabs"; import { BranchesPanel } from "./log/BranchesPanel"; -import { CommitDetails } from "./log/CommitDetails"; +import { CommitDetails, useDiffLocation } from "./log/CommitDetails"; import { CommitList } from "./log/CommitList"; +import { FileHistoryDiffPreview } from "./log/FileHistoryDiffPreview"; import { FilterBar } from "./log/FilterBar"; import { useLogRepositories, useReadOnlyLog } from "./log/logHooks"; import { PANE_STYLE } from "./log/shared"; @@ -157,6 +158,10 @@ export function LogView() { const comparison = useGitLog((s) => !!s.logTabs.find((t) => t.id === (scope ?? s.shownLog))?.comparison); const showBranches = useLogOptions((s) => s.showBranches) && !comparison; const showDetails = useLogOptions((s) => s.showDetails); + // IDEA's file history shows the file's diff beside the revisions; "Editor" opens it in a tab instead. + const diffPreview = useLogOptions((s) => s.diffPreview); + const diffLocation = useDiffLocation(true); + const historyDiff = diffPreview && diffLocation !== "editor" ? diffLocation : null; const historyPath = useGitLog((s) => { const tab = s.logTabs.find((t) => t.id === (scope ?? s.shownLog)); return tab?.kind === "history" && stripSlash(tab.target) !== tab.repo ? tab.target : null; @@ -260,27 +265,46 @@ export function LogView() { if (historyPath && historyPath === filePath) return ( -