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 ( -