From 834fac89b446e3d05bfb1017487132407fc3e144 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Fri, 20 Nov 2026 19:40:33 +0800 Subject: [PATCH] Align selection history preview and revision table (#4764) The selection history dialog aligns its preview and revision table and keeps both usable in narrow panes. --- e2e/selectionHistoryLayout.spec.ts | 94 +++++++++++++++ src/features/vcs/LocalHistory.module.css | 13 --- src/features/vcs/SelectionHistory.module.css | 54 +++++++-- src/features/vcs/SelectionHistory.tsx | 107 +++++++++++------- .../vcs/__tests__/selectionHistory.test.tsx | 9 +- 5 files changed, 215 insertions(+), 62 deletions(-) create mode 100644 e2e/selectionHistoryLayout.spec.ts diff --git a/e2e/selectionHistoryLayout.spec.ts b/e2e/selectionHistoryLayout.spec.ts new file mode 100644 index 000000000..234ade8a4 --- /dev/null +++ b/e2e/selectionHistoryLayout.spec.ts @@ -0,0 +1,94 @@ +import type { EditorView } from "@codemirror/view"; +import { expect, stubDesktop, test } from "./fixtures"; + +test("selection history keeps a full-width diff above a keyboard-resizable revision table", async ({ + workbench: page, +}) => { + await page.setViewportSize({ width: 1140, height: 740 }); + const filename = "QuarterlyCrossBorderSettlementReconciliationProjection.ts"; + const path = `/dev/acme-api/modules/${filename}`; + const lastMessage = "Introduce the reconciliation projection for pending cross-border merchant settlements"; + await page.evaluate(async (path) => { + const backend = "/src/editor/core/backend.ts"; + (await import(/* @vite-ignore */ backend)) + .docBackend() + .files.set(path, "export const pending = 0;\nconst projection = uncommitted;\n"); + const service = "/src/workbench/contributions.ts"; + await (await import(/* @vite-ignore */ service)).editorService().openFile(path); + }, path); + const editor = page.locator(".cm-content"); + await expect(editor).toContainText("uncommitted"); + await editor.evaluate((el) => { + const view = (el as HTMLElement & { cmTile: { view: EditorView } }).cmTile.view; + const line = view.state.doc.line(2); + view.dispatch({ selection: { anchor: line.from, head: line.to } }); + view.focus(); + }); + await stubDesktop(page); + await page.evaluate( + async ({ path, lastMessage }) => { + window.__ipc.handlers.cancel_request = () => null; + window.__ipc.handlers.vcs_block_history = () => ({ + headLines: [1, 1], + revisions: Array.from({ length: 22 }, (_, i) => ({ + id: (i + 16).toString(16).padStart(40, "0"), + shortId: (i + 16).toString(16).padStart(7, "0"), + author: "Alexandra Reconciliation Coordinator", + email: "coordinator@example.test", + timeMs: 1738329600000 - i * 86400000, + summary: i === 21 ? lastMessage : `Update reconciliation estimate ${22 - i}`, + path, + before: `const projection = estimate${21 - i};\n`, + after: `const projection = estimate${22 - i};\n`, + beforeLine: 1, + afterLine: 1, + })), + }); + const actions = "/src/platform/actions.ts"; + await (await import(/* @vite-ignore */ actions)).executeAction("vcs.showHistoryForSelection"); + }, + { path, lastMessage }, + ); + + const diff = page.locator(".cm-mergeView"); + await expect(diff).toContainText("uncommitted"); + const revisions = page.getByRole("grid", { name: "Revisions" }); + const history = revisions.or(page.getByRole("listbox", { name: "Revisions" })); + await expect(history).toBeVisible(); + const preview = (await diff.boundingBox())!; + const list = (await history.boundingBox())!; + expect(list.y).toBeGreaterThanOrEqual(preview.y + preview.height - 1); + expect(preview.width).toBeGreaterThanOrEqual(list.width - 2); + + await expect(revisions.getByRole("columnheader")).toHaveText(["Revision", "Date", "Author", "Message"]); + const divider = page.getByRole("separator", { name: "Revisions", exact: true }); + await expect(divider).toHaveAttribute("aria-orientation", "horizontal"); + const initial = (await divider.boundingBox())!.y; + await divider.press("ArrowUp"); + await expect.poll(async () => (await divider.boundingBox())!.y).toBeLessThan(initial); + await expect(revisions.getByRole("row", { selected: true })).toContainText("Local Changes"); + + await page.setViewportSize({ width: 490, height: 620 }); + await expect(divider).toHaveAttribute("aria-orientation", "horizontal"); + await expect(page.getByTitle(`${filename}:2-2`, { exact: true })).toBeVisible(); + const body = revisions.getByRole("rowgroup"); + await body.press("End"); + const last = revisions.getByRole("row", { selected: true }); + await expect(last.getByRole("gridcell", { name: lastMessage, exact: true })).toHaveAttribute("title", lastMessage); + await expect + .poll(async () => { + const listBounds = (await body.boundingBox())!; + const rowBounds = (await last.boundingBox())!; + return Math.max(listBounds.y - rowBounds.y, rowBounds.y + rowBounds.height - listBounds.y - listBounds.height); + }) + .toBeLessThanOrEqual(1); + const headers = revisions.getByRole("columnheader"); + const cells = last.getByRole("gridcell"); + for (let i = 0; i < 4; i++) { + expect( + Math.abs((await headers.nth(i).boundingBox())!.x - (await cells.nth(i).boundingBox())!.x), + ).toBeLessThanOrEqual(1); + } + expect(await body.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1); + await expect(diff).toContainText("estimate1"); +}); diff --git a/src/features/vcs/LocalHistory.module.css b/src/features/vcs/LocalHistory.module.css index 194cea6ed..a2b4ae605 100644 --- a/src/features/vcs/LocalHistory.module.css +++ b/src/features/vcs/LocalHistory.module.css @@ -8,13 +8,6 @@ .resizable { min-width: 0; } -.sidebar { - flex: none; - width: 260px; - display: flex; - flex-direction: column; - border-right: 1px solid var(--border); -} .header { flex: none; height: var(--h-header); @@ -77,12 +70,6 @@ .deletedPath { text-decoration: line-through; } -.diff { - flex: 1; - min-width: 0; - display: flex; - flex-direction: column; -} .message { padding: var(--space-4); color: var(--fg-faint); diff --git a/src/features/vcs/SelectionHistory.module.css b/src/features/vcs/SelectionHistory.module.css index 04bc54f19..a8bbb57f9 100644 --- a/src/features/vcs/SelectionHistory.module.css +++ b/src/features/vcs/SelectionHistory.module.css @@ -1,18 +1,56 @@ .range { - flex: none; + min-width: 0; + max-width: min(60%, 52ch); + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; color: var(--fg-subtle); font-size: var(--fs-small); } -.summary, -.meta { +.table { + --list-inset: var(--space-1); + --history-columns: minmax(56px, 9%) minmax(68px, 18%) minmax(56px, 18%) minmax(0, 1fr); + flex: 1; + min-height: 0; + min-width: 0; + display: flex; + flex-direction: column; +} +.columns { + display: grid; + grid-template-columns: var(--history-columns); + align-items: center; + gap: var(--space-2); + width: 100%; + min-width: 0; +} +.heading { + flex: none; + min-height: var(--h-row); + padding-inline: calc(var(--list-inset) + var(--space-2)); + border-bottom: 1px solid var(--border); + color: var(--fg-muted); + font-size: var(--fs-small); + overflow: hidden; + scrollbar-gutter: stable; +} +.heading::-webkit-scrollbar { + width: 10px; +} +.list { + flex: 1; + scrollbar-gutter: stable; + font-size: var(--fs-ui); +} +.cell { + min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } -.summary { - color: var(--fg-emphasis); -} -.meta { +.cell[role="gridcell"]:not(:last-child) { color: var(--fg-subtle); - font-size: var(--fs-small); +} +.cell[role="gridcell"]:nth-child(-n + 2) { + font-variant-numeric: tabular-nums; } diff --git a/src/features/vcs/SelectionHistory.tsx b/src/features/vcs/SelectionHistory.tsx index f92a5eab9..1d02d9fb3 100644 --- a/src/features/vcs/SelectionHistory.tsx +++ b/src/features/vcs/SelectionHistory.tsx @@ -7,7 +7,7 @@ import { useEffect, useState } from "react"; import type { BlockHistory, BlockRevision } from "@/bindings"; import { call, commands, isCancelled, nextRequestId } from "@/platform/ipc"; -import { List, Spinner, T } from "@/ui"; +import { List, Spinner, SplitGroup, SplitHandle, SplitPanel, T } from "@/ui"; import type { EditorInput } from "@/workbench/contributions"; import { DiffEditor } from "./DiffEditor"; import { diffInput, type DiffSide } from "./diffInput"; @@ -23,6 +23,7 @@ export type HistoryRow = | { kind: "revision"; revision: BlockRevision }; const HEAD = "HEAD"; +const COLUMNS = ["Revision", "Date", "Author", "Message"] as const; /** Lines `from..=to` of `text`, each ending with a line break (as Git prints a block). */ export function blockOf(text: string, [from, to]: readonly [number, number]): string { @@ -78,6 +79,7 @@ export function SelectionHistoryEditor({ input }: { input: EditorInput }) { const rows = history ? historyRows(history, blockOf(data.text, data.lines)) : []; const current = rows[Math.min(active, rows.length - 1)]; const [from, to] = data.lines; + const range = `${baseName(data.path)}:${from + 1}-${to + 1}`; let detail; if (!current) @@ -97,13 +99,23 @@ export function SelectionHistoryEditor({ input }: { input: EditorInput }) { } return ( -
-
+ + + {detail} + + +
History for Selection - {`${baseName(data.path)}:${from + 1}-${to + 1}`} + + {range} +
{error ? (
{error}
@@ -112,43 +124,60 @@ export function SelectionHistoryEditor({ input }: { input: EditorInput }) {
) : ( - (row.kind === "local" ? "local" : row.revision.id)} - activeIndex={Math.min(active, rows.length - 1)} - onActiveChange={setActive} - onActivate={(_row, i) => setActive(i)} - rowHeight={38} - aria-label="Revisions" - className={layout.list} - empty={ - - {history.headLines ? tx`No commits changed these lines` : tx`These lines are not committed yet`} - - } - renderItem={(row) => - row.kind === "local" ? ( - - - Local Changes - - - Not Committed Yet - +
+
+ {COLUMNS.map((label) => ( + + {label} - ) : ( - - {row.revision.summary} - - {`${row.revision.shortId} · ${row.revision.author} · ${formatTime(row.revision.timeMs)}`} - + ))} +
+ (row.kind === "local" ? "local" : row.revision.id)} + activeIndex={Math.min(active, rows.length - 1)} + onActiveChange={setActive} + onActivate={(_row, i) => setActive(i)} + tableBody={{ headerRows: 1 }} + className={styles.list} + empty={ + + {history.headLines ? tx`No commits changed these lines` : tx`These lines are not committed yet`} - ) - } - /> + } + renderItem={(row) => { + const revision = row.kind === "revision" ? row.revision : null; + const cells = [ + revision?.shortId ?? "", + formatTime(revision?.timeMs), + revision?.author ?? "", + revision?.summary ?? tx("Local Changes"), + ]; + return ( + + {cells.map((value, i) => ( + + {value} + + ))} + + ); + }} + /> +
)} -
-
{detail}
- + + ); } diff --git a/src/features/vcs/__tests__/selectionHistory.test.tsx b/src/features/vcs/__tests__/selectionHistory.test.tsx index 50f81fbd8..3de2e7465 100644 --- a/src/features/vcs/__tests__/selectionHistory.test.tsx +++ b/src/features/vcs/__tests__/selectionHistory.test.tsx @@ -1,5 +1,5 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; -import { fireEvent, render, screen, waitFor } from "@testing-library/react"; +import { fireEvent, render, screen, waitFor, within } from "@testing-library/react"; import { EditorState } from "@codemirror/state"; import type { BlockHistory, BlockRevision } from "@/bindings"; @@ -108,7 +108,12 @@ describe("History for Selection tab", () => { await waitFor(() => expect(screen.getByTestId("diff").textContent).toBe("bbbbbbb^: two\nthree\n| bbbbbbb: TWO\nthree\n"), ); - expect(screen.getByText(/^bbbbbbb · Ada · /)).toBeTruthy(); + const row = screen.getByRole("row", { name: /bbbbbbb.*Ada.*Shout two/ }); + expect( + within(row) + .getAllByRole("gridcell") + .map((cell) => cell.textContent), + ).toEqual(["bbbbbbb", expect.any(String), "Ada", "Shout two"]); }); it("says why there is nothing to show", async () => {