From c61ddbff3d4e037720c583eb8838e5b8d41bf779 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Mon, 23 Nov 2026 09:13:30 +0800 Subject: [PATCH] fix(vcs): make Git Log commit choices easier to scan (#5250) The Git Log commit chooser now gives its results the full dialog width and sizes the list to the number of candidates. Previously the list could be clipped inside a fixed-height area. Each row separates the subject from the hash, author and timestamp. The search field keeps keyboard focus while the arrow keys move the selection. --- e2e/gitLogCommitChooser.spec.ts | 104 ++++++++++++++++++++++ src/features/vcs/CommitChooser.module.css | 65 ++++++++++++++ src/features/vcs/CommitChooser.tsx | 81 ++++++++++++++--- 3 files changed, 239 insertions(+), 11 deletions(-) create mode 100644 e2e/gitLogCommitChooser.spec.ts create mode 100644 src/features/vcs/CommitChooser.module.css diff --git a/e2e/gitLogCommitChooser.spec.ts b/e2e/gitLogCommitChooser.spec.ts new file mode 100644 index 000000000..c531a5205 --- /dev/null +++ b/e2e/gitLogCommitChooser.spec.ts @@ -0,0 +1,104 @@ +import { expect, stubDesktop, test } from "./fixtures"; + +const rootSubject = "Start warehouse reporting"; +const mergeSubject = "Merge reporting changes"; +const firstSubject = "Align regional settlement totals with the warehouse ledger before monthly reconciliation closes"; +const secondSubject = "Keep archived settlement adjustments in the regional audit trail after the ledger is rebuilt"; + +test("Git Log commit choices fit their rows and navigate by keyboard after filtering", async ({ workbench: page }) => { + await page.setViewportSize({ width: 1040, height: 700 }); + await stubDesktop(page); + await page.evaluate( + async ({ mergeSubject, firstSubject, secondSubject, rootSubject }) => { + const root = "/dev/acme-api"; + const changes = [ + [mergeSubject, "Merge Author", [1, 2]], + [firstSubject, "Priya Kapoor", [3]], + [secondSubject, "Morgan Olsen", [3]], + [rootSubject, "Initial Author", []], + ] as const; + const id = (i: number) => String(i + 1).repeat(40); + const commits = changes.map(([summary, author, parents], i) => ({ + id: id(i), + shortId: id(i).slice(0, 8), + parents: parents.map(id), + refs: i === 0 ? ["HEAD", "main"] : [], + author, + email: "author@example.com", + timeMs: Date.UTC(2026, 10, 15 - i, 10 + i, 30), + summary, + message: summary, + })); + const handlers = window.__ipc.handlers; + handlers.vcs_log = ({ query }) => { + const { skip, limit, range } = query as { skip: number; limit: number; range?: string }; + return range ? [] : commits.slice(skip, limit ? skip + limit : undefined); + }; + handlers.vcs_log_refs = () => ({}); + handlers.vcs_log_users = () => []; + handlers.vcs_branches = () => []; + handlers.vcs_branch_info = () => ({ head: "main", headCommit: id(0), ahead: 0, behind: 0 }); + handlers.vcs_config_get = () => null; + handlers.vcs_commit_files = () => []; + handlers.vcs_log_details_batch = ({ revisions }) => + (revisions as string[]).map(() => ({ message: "", containingBranches: [], signature: "N" })); + const vcsModule = "/src/features/vcs/store.ts"; + const contextModule = "/src/platform/context.ts"; + const actionsModule = "/src/platform/actions.ts"; + const { useVcs } = await import(/* @vite-ignore */ vcsModule); + const { setContext } = await import(/* @vite-ignore */ contextModule); + const { executeAction } = await import(/* @vite-ignore */ actionsModule); + useVcs.setState({ available: true, root, repo: root, roots: [root], branchesLoaded: true }); + setContext("vcsAvailable", true); + await executeAction("vcs.showLog"); + }, + { mergeSubject, firstSubject, secondSubject, rootSubject }, + ); + + const log = page.getByRole("listbox", { name: "Commits", exact: true }); + const merge = log.getByRole("option", { name: new RegExp(mergeSubject) }); + await merge.click(); + await log.press("ArrowRight"); + const chooser = page.getByRole("dialog", { name: "Select Parent Commit", exact: true }); + const options = chooser.getByRole("option"); + const filter = chooser.getByRole("combobox", { name: "Search commits" }); + await expect(filter).toBeFocused(); + await expect(options).toHaveCount(2); + const before = (await chooser.boundingBox())!; + expect(before.height).toBeLessThan(200); + const first = options.filter({ hasText: firstSubject }); + const subject = first.getByText(firstSubject, { exact: true }); + const author = first.getByText("Priya Kapoor", { exact: true }); + const hash = first.getByText("22222222", { exact: true }); + await expect(subject).toHaveCSS("font-size", "13px"); + await expect(author).toHaveCSS("font-size", "12px"); + expect((await subject.boundingBox())!.y).toBeLessThan((await hash.boundingBox())!.y); + await expect(subject.locator("..")).toHaveAttribute("title", /Priya Kapoor/); + + await page.setViewportSize({ width: 440, height: 520 }); + const narrow = (await chooser.boundingBox())!; + expect(narrow.x + narrow.width).toBeLessThanOrEqual(440); + expect(await chooser.evaluate((node) => node.scrollWidth - node.clientWidth)).toBeLessThanOrEqual(1); + await filter.fill("No such change"); + await expect(chooser.getByText("No commits", { exact: true })).toBeVisible(); + await filter.press("Enter"); + await expect(chooser).toBeVisible(); + await filter.fill("Morgan Olsen"); + await expect(options).toHaveCount(1); + await expect(options.first()).toContainText(secondSubject); + await filter.fill(""); + await expect(options).toHaveCount(2); + await filter.press("ArrowDown"); + await expect(options.filter({ hasText: secondSubject })).toHaveAttribute("aria-selected", "true"); + await filter.press("Enter"); + await expect(chooser).toBeHidden(); + await expect(log.getByRole("option", { name: new RegExp(secondSubject) })).toHaveAttribute("aria-selected", "true"); + + await log.getByRole("option", { name: new RegExp(rootSubject) }).click(); + await log.press("ArrowLeft"); + const children = page.getByRole("dialog", { name: "Select Child Commit", exact: true }); + await expect(children.getByRole("option")).toHaveCount(2); + await children.getByRole("option", { name: new RegExp(firstSubject) }).click(); + await expect(children).toBeHidden(); + await expect(log.getByRole("option", { name: new RegExp(firstSubject) })).toHaveAttribute("aria-selected", "true"); +}); diff --git a/src/features/vcs/CommitChooser.module.css b/src/features/vcs/CommitChooser.module.css new file mode 100644 index 000000000..4817177ce --- /dev/null +++ b/src/features/vcs/CommitChooser.module.css @@ -0,0 +1,65 @@ +.search { + display: flex; + padding: var(--space-2) var(--space-3); +} + +.search > * { + flex: 1; + min-width: 0; +} + +.results { + display: flex; + flex-direction: column; + max-height: max(84px, calc(100vh - 144px)); + margin-bottom: var(--space-2); +} + +.list { + flex: 1; +} + +.choice { + display: flex; + flex-direction: column; + width: 100%; + min-width: 0; +} + +.choice > span { + pointer-events: none; +} + +.subject, +.author, +.date { + overflow: hidden; + text-overflow: ellipsis; +} + +.subject { + font-size: var(--fs-ui); +} + +.metadata { + display: flex; + gap: var(--space-2); + align-items: baseline; + color: var(--fg-muted); + font-size: var(--fs-small); +} + +.hash { + flex: none; + font-family: var(--font-mono); +} + +.author { + flex: 1; + min-width: 0; +} + +.date { + flex: none; + max-width: 50%; +} diff --git a/src/features/vcs/CommitChooser.tsx b/src/features/vcs/CommitChooser.tsx index a7eaf894c..550a10244 100644 --- a/src/features/vcs/CommitChooser.tsx +++ b/src/features/vcs/CommitChooser.tsx @@ -1,9 +1,14 @@ -import { useState } from "react"; +import { useId, useState, type KeyboardEvent } from "react"; import type { Commit } from "@/bindings"; -import { Dialog, List, SearchField } from "@/ui"; +import { tx } from "@/platform/i18n"; +import { Dialog, List, SearchField, T, listNavigate } from "@/ui"; import { openDialog } from "./dialogs"; +import { formatTime } from "./model"; import { commitKey } from "./multiRoot"; -import { useRowHeight } from "@/ui/density"; +import styles from "./CommitChooser.module.css"; + +const ROW_HEIGHT = 42; +const VISIBLE_ROWS = 8; export function chooseLogCommit(commits: Commit[], title: string): Promise { return new Promise((resolve) => { @@ -29,22 +34,76 @@ function CommitChooser({ title: string; onDone: (commit: Commit | null) => void; }) { - const rowHeight = useRowHeight(26); + const listId = useId(); const [query, setQuery] = useState(""); - const shown = commits.filter((c) => - `${c.id} ${c.summary} ${c.author}`.toLocaleLowerCase().includes(query.toLocaleLowerCase()), + const [active, setActive] = useState(0); + const filter = query.toLocaleLowerCase(); + const shown = commits.filter((commit) => + `${commit.id} ${commit.summary} ${commit.author}`.toLocaleLowerCase().includes(filter), ); + const selected = Math.min(active, shown.length - 1); + const onKeyDown = (event: KeyboardEvent) => { + if (event.nativeEvent.isComposing) return; + if (event.key === "Enter") { + event.preventDefault(); + if (shown[selected]) onDone(shown[selected]); + } else if (event.key === "ArrowDown" || event.key === "ArrowUp") { + const next = listNavigate(event.key, { items: shown, active: selected, wrap: true }); + if (next === null) return; + event.preventDefault(); + setActive(next); + } + }; + return ( onDone(null)} width={520}> - -
+
+ = 0 ? `${listId}-${selected}` : undefined} + value={query} + onChange={(value) => { + setQuery(value); + setActive(0); + }} + onKeyDown={onKeyDown} + placeholder="Search commits" + aria-label="Search commits" + /> +
+
`${c.shortId} ${c.summary} — ${c.author}`} + activeIndex={selected} + onActiveChange={setActive} onActivate={onDone} - rowHeight={rowHeight} - aria-label={title} + focusable={false} + rowHeight={ROW_HEIGHT} + aria-label={tx(title)} + empty={No commits} + className={styles.list} + renderItem={(commit) => { + const date = formatTime(commit.timeMs); + return ( + + {commit.summary} + + {commit.shortId} + {commit.author} + {date && {date}} + + + ); + }} />