From d31699c86aca0d0448840041ba9dbcd66939f36d Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Sat, 21 Nov 2026 07:59:59 +0800 Subject: [PATCH] fix(vcs): align the file revision chooser (#4919) fix(vcs): align the file revision chooser --- e2e/fileRevisionLayout.spec.ts | 104 ++++++++++++++++++ .../vcs/FileRevisionChooser.module.css | 55 ++++++--- src/features/vcs/FileRevisionChooser.tsx | 40 ++++++- src/platform/locales/text/en.json | 1 + 4 files changed, 180 insertions(+), 20 deletions(-) create mode 100644 e2e/fileRevisionLayout.spec.ts diff --git a/e2e/fileRevisionLayout.spec.ts b/e2e/fileRevisionLayout.spec.ts new file mode 100644 index 000000000..1f7bd6ef2 --- /dev/null +++ b/e2e/fileRevisionLayout.spec.ts @@ -0,0 +1,104 @@ +import { expect, ipcCalls, openFromTree, stubDesktop, test } from "./fixtures"; + +test("the file revision chooser previews commit messages and compares the selected revision", async ({ + workbench: page, +}) => { + await openFromTree(page, "build.gradle.kts"); + await stubDesktop(page); + await page.evaluate(async () => { + const root = "/dev/acme-api"; + const path = `${root}/build.gradle.kts`; + const latest = "123abcd000000000000000000000000000000000"; + const previous = "456efab000000000000000000000000000000000"; + window.__ipc.handlers.vcs_revision_files = () => ["build.gradle.kts"]; + window.__ipc.handlers.vcs_log = () => [ + { + id: latest, + shortId: "123abcd", + author: "Lena Park", + timeMs: Date.now(), + summary: "Update reviewed totals", + message: "Update reviewed totals", + messageTruncated: true, + }, + { + id: previous, + shortId: "456efab", + author: "Morgan Chen", + timeMs: Date.UTC(2025, 9, 18), + summary: "Include October adjustments", + message: "Include October adjustments\n\nUse the corrected quantities from the October review.", + }, + ]; + window.__ipc.handlers.vcs_log_details_batch = () => [ + { message: "Update reviewed totals\n\nUse the totals reviewed by the release team." }, + ]; + window.__ipc.handlers.vcs_file_at = () => "val reviewedTotal = 28\n"; + window.__ipc.handlers.vcs_file_mode = () => "100644"; + + const storeModule = "/src/features/vcs/store.ts"; + const historyModule = "/src/features/vcs/fileRevisions.ts"; + const contextModule = "/src/platform/context.ts"; + const actionsModule = "/src/platform/actions.ts"; + const { useVcs } = await import(/* @vite-ignore */ storeModule); + const { hasFileHistory, trackFileHistory } = await import(/* @vite-ignore */ historyModule); + const { setContext } = await import(/* @vite-ignore */ contextModule); + const { executeAction } = await import(/* @vite-ignore */ actionsModule); + useVcs.setState({ roots: [root], heads: { [root]: { headCommit: latest } }, statusLoaded: true }); + trackFileHistory(); + await expectFileHistory(); + setContext("vcsAvailable", true); + await executeAction("vcs.compareWithRevision", path); + + async function expectFileHistory() { + for (let i = 0; i < 20 && !hasFileHistory(path); i++) { + await new Promise((resolve) => setTimeout(resolve, 10)); + } + if (!hasFileHistory(path)) throw new Error("The sample file has no tracked history"); + } + }); + + const chooser = page.getByRole("dialog", { name: "Compare with Revision…" }); + const search = chooser.getByRole("textbox", { name: "Search file revisions" }); + const revisions = chooser.getByRole("listbox", { name: "File revisions" }); + const message = chooser.getByRole("region", { name: "Commit message" }); + await expect(revisions.getByRole("option")).toHaveCount(2); + await expect(message).toContainText("Use the totals reviewed by the release team."); + await expect + .poll(() => ipcCalls(page, "vcs_log_details_batch")) + .toEqual([ + expect.objectContaining({ + repo: "/dev/acme-api", + revisions: ["123abcd000000000000000000000000000000000"], + }), + ]); + + const firstAuthor = await revisions.getByText("Lena Park", { exact: true }).boundingBox(); + const secondAuthor = await revisions.getByText("Morgan Chen", { exact: true }).boundingBox(); + expect(Math.abs(firstAuthor!.x - secondAuthor!.x)).toBeLessThan(1); + await search.press("Tab"); + await expect(message).toBeFocused(); + await search.press("ArrowDown"); + await expect(revisions.getByRole("option", { name: /Morgan Chen/ })).toHaveAttribute("aria-selected", "true"); + await expect(message).toContainText("Use the corrected quantities from the October review."); + + await page.setViewportSize({ width: 480, height: 350 }); + const listBox = (await revisions.boundingBox())!; + const messageBox = (await message.boundingBox())!; + expect(messageBox.y).toBeGreaterThanOrEqual(listBox.y + listBox.height - 1); + expect(messageBox.y + messageBox.height).toBeLessThanOrEqual(350); + await search.fill("unmatched"); + await expect(revisions).toContainText("No commits"); + await expect(message).not.toContainText("Use the corrected quantities from the October review."); + await search.fill("October adjustments"); + await expect(revisions.getByRole("option")).toHaveCount(1); + await expect(message).toContainText("Use the corrected quantities from the October review."); + await search.press("Enter"); + await expect(chooser).toBeHidden(); + await expect + .poll(() => ipcCalls(page, "vcs_file_at")) + .toContainEqual({ + path: "/dev/acme-api/build.gradle.kts", + rev: "456efab000000000000000000000000000000000", + }); +}); diff --git a/src/features/vcs/FileRevisionChooser.module.css b/src/features/vcs/FileRevisionChooser.module.css index 393923aef..3457ba820 100644 --- a/src/features/vcs/FileRevisionChooser.module.css +++ b/src/features/vcs/FileRevisionChooser.module.css @@ -1,23 +1,31 @@ -.search { - padding: 8px 10px; - border-bottom: 1px solid var(--border-popup); -} -.body { - height: 280px; +.dialog > [data-dialog-body] { display: flex; flex-direction: column; - padding: 4px 0; + overflow: hidden; +} +.search { + flex: none; + padding: var(--space-2) var(--space-3); + border-bottom: 1px solid var(--border-popup); +} +.revisions { + display: flex; + flex-direction: column; + flex: 1; + min-height: 0; + padding-block: var(--space-1); } .list { flex: 1; min-height: 0; } .error { - padding: 8px 10px; + padding: var(--space-2) var(--space-3); color: var(--danger); } .row { - display: flex; + display: grid; + grid-template-columns: 9ch minmax(0, min(45%, 14em)) minmax(0, 1fr); align-items: center; gap: var(--space-3); min-width: 0; @@ -29,18 +37,35 @@ } .date { color: var(--fg-subtle); - flex-shrink: 0; + font-variant-numeric: tabular-nums; } .author { - flex: 0 0 110px; color: var(--fg-secondary); } -.author, -.subject { +.row > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } -.subject { - flex: 1; +.details { + flex: 0 0 min(40%, 144px); + min-height: 0; + overflow: auto; + padding: var(--space-2) var(--space-3) var(--space-3); + border-top: 1px solid var(--border-popup); + font-size: var(--fs-ui); +} +.details:focus-visible { + outline: 1px solid var(--accent); + outline-offset: -2px; +} +.caption { + margin-bottom: var(--space-2); + color: var(--fg-secondary); +} +.message { + color: var(--fg-strong); + line-height: 1.4; + white-space: pre-wrap; + overflow-wrap: anywhere; } diff --git a/src/features/vcs/FileRevisionChooser.tsx b/src/features/vcs/FileRevisionChooser.tsx index 1b8db5fa5..e754f7bbf 100644 --- a/src/features/vcs/FileRevisionChooser.tsx +++ b/src/features/vcs/FileRevisionChooser.tsx @@ -2,12 +2,14 @@ import { useEffect, useState, type KeyboardEvent } from "react"; import type { Commit } from "@/bindings"; import { call, commands, nextRequestId } from "@/platform/ipc"; import { tx } from "@/platform/i18n"; -import { Dialog, List, SearchField, Spinner, T, listNavigate } from "@/ui"; +import { Dialog, List, SearchField, Spinner, T, listNavigate, selectableText } from "@/ui"; import { openDialog } from "./dialogs"; import { annotateAtRevision } from "./annotateRevision"; import { openVcsDiff } from "./diffInput"; import { hasFileHistory } from "./fileRevisions"; +import { useCommitDetails } from "./logDetails"; import { formatTime } from "./model"; +import type { RepoCommit } from "./multiRoot"; import { repositoryPath } from "./repositoryPaths"; import { repoOf } from "./store"; import styles from "./FileRevisionChooser.module.css"; @@ -59,6 +61,15 @@ export function annotateFileRevision(path: string | null | undefined) { )); } +function CommitMessage({ commit }: { commit: RepoCommit }) { + const { details } = useCommitDetails(commit, commit.messageTruncated === true); + return ( +
+ {details?.message ?? (commit.message || commit.summary)} +
+ ); +} + function FileRevisionChooser({ path, repo, @@ -109,6 +120,7 @@ function FileRevisionChooser({ `${c.id} ${formatTime(c.timeMs)} ${c.author} ${c.summary}`.toLocaleLowerCase().includes(q), ); const idx = Math.min(active, items.length - 1); + const selected = items[idx]; const onKeyDown = (e: KeyboardEvent) => { if (e.key === "Enter") { e.preventDefault(); @@ -122,7 +134,16 @@ function FileRevisionChooser({ } }; return ( - +
-
+
{error ? (
{error} @@ -153,7 +174,6 @@ function FileRevisionChooser({ onActivate={onChoose} focusable={false} hoverSelects - rowHeight={28} aria-label="File revisions" empty={No commits} className={styles.list} @@ -162,12 +182,22 @@ function FileRevisionChooser({ {c.shortId} {formatTime(c.timeMs)} {c.author} - {c.summary} )} /> )}
+
+ + {selected && } +
); } diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index 20898ad73..9eb861674 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -458,6 +458,7 @@ "Show File at Revision": "Show File at Revision", "Search file revisions": "Search file revisions", "File revisions": "File revisions", + "Commit message": "Commit message", "The current line has no committed revision": "The current line has no committed revision", "JAR Application": "JAR Application", "Run an executable JAR": "Run an executable JAR",