diff --git a/e2e/localHistoryLayout.spec.ts b/e2e/localHistoryLayout.spec.ts new file mode 100644 index 000000000..f4d9faf07 --- /dev/null +++ b/e2e/localHistoryLayout.spec.ts @@ -0,0 +1,50 @@ +import { expect, ipcCalls, openFromTree, stubDesktop, test } from "./fixtures"; + +test("Local History gives the diff room and keeps revision selection across layouts", async ({ workbench: page }) => { + await page.setViewportSize({ width: 1180, height: 700 }); + await openFromTree(page, "build.gradle.kts"); + await stubDesktop(page); + await page.evaluate(async () => { + const file = "/dev/acme-api/build.gradle.kts"; + const entries = [ + { id: "after", path: file, timestampMs: 2000, label: "Saved", size: 31, kind: "snapshot" }, + { id: "before", path: file, timestampMs: 1000, label: "Original", size: 34, kind: "snapshot" }, + ]; + window.__ipc.handlers.history_list_dir = () => ({ entries, deleted: [] }); + window.__ipc.handlers.history_content = ({ id }) => + id === "before" ? 'val reportMode = "summary"\n' : 'val reportMode = "detailed"\n'; + window.__ipc.handlers.vcs_file_mode = () => null; + window.__ipc.handlers.fs_probe = () => ({ size: 32, binary: false, tooLarge: false }); + + const actionsModule = "/src/platform/actions.ts"; + const { executeAction } = await import(/* @vite-ignore */ actionsModule); + await executeAction("vcs.localHistory", file); + }); + + const revisions = page.getByRole("listbox", { name: "Revisions" }); + await expect(revisions.getByRole("option", { name: /Saved/ })).toBeVisible(); + const separator = page.getByRole("separator", { name: "Revisions" }); + await expect(separator).toHaveAttribute("aria-orientation", "vertical"); + const initialWidth = (await revisions.boundingBox())!.width; + await separator.press("ArrowLeft"); + await expect.poll(async () => (await revisions.boundingBox())!.width).toBeLessThan(initialWidth); + + const original = revisions.getByRole("option", { name: /^Original/ }); + await original.click(); + await expect(original).toHaveAttribute("aria-selected", "true"); + await expect.poll(async () => ipcCalls(page, "history_content")).toContainEqual({ id: "before" }); + + await page.setViewportSize({ width: 480, height: 620 }); + await expect(separator).toHaveAttribute("aria-orientation", "horizontal"); + await expect(original).toHaveAttribute("aria-selected", "true"); + const diff = page.locator(".cm-mergeView").filter({ hasText: "summary" }); + await expect(diff).toBeVisible(); + const listBox = (await revisions.boundingBox())!; + const diffBox = (await diff.boundingBox())!; + expect(diffBox.y).toBeGreaterThanOrEqual(listBox.y + listBox.height); + expect(diffBox.width).toBeGreaterThanOrEqual(listBox.width - 2); + + await page.setViewportSize({ width: 1180, height: 700 }); + await expect(separator).toHaveAttribute("aria-orientation", "vertical"); + await expect(original).toHaveAttribute("aria-selected", "true"); +}); diff --git a/src/features/vcs/LocalHistory.module.css b/src/features/vcs/LocalHistory.module.css index b361caa96..194cea6ed 100644 --- a/src/features/vcs/LocalHistory.module.css +++ b/src/features/vcs/LocalHistory.module.css @@ -5,6 +5,9 @@ display: flex; background: var(--bg-app); } +.resizable { + min-width: 0; +} .sidebar { flex: none; width: 260px; @@ -18,7 +21,7 @@ display: flex; align-items: center; gap: var(--space-2); - padding: 0 8px 0 12px; + padding: 0 var(--space-2) 0 var(--space-3); border-bottom: 1px solid var(--border); } .title { @@ -26,6 +29,14 @@ color: var(--fg-emphasis); font-weight: 500; } +.resizable .title { + min-width: 0; + font-size: var(--fs-ui); + font-weight: 600; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} .list { flex: 1; } @@ -35,14 +46,36 @@ min-width: 0; gap: var(--space-0-5); } -.time { - color: var(--fg-emphasis); +.resizable .entry { + width: 100%; + line-height: 1.2; } -.label { - color: var(--fg-subtle); - font-size: var(--fs-small); +.primaryRow { + display: flex; + align-items: center; + gap: var(--space-1-5); + color: var(--fg-strong); + font-size: var(--fs-ui); +} +.primary, +.meta, +.path, +.deletedPath { overflow: hidden; text-overflow: ellipsis; + white-space: nowrap; +} +.meta, +.path, +.deletedPath { + color: var(--fg-muted); + font-size: var(--fs-small); +} +.meta { + font-variant-numeric: tabular-nums; +} +.deletedPath { + text-decoration: line-through; } .diff { flex: 1; @@ -51,33 +84,11 @@ flex-direction: column; } .message { - padding: 16px; + padding: var(--space-4); color: var(--fg-faint); text-align: center; } -.path, -.deletedPath { - color: var(--fg); - font-size: var(--fs-small); - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; -} -.deletedPath { - color: var(--fg-muted); - text-decoration: line-through; -} -.labelRow { - display: flex; - align-items: center; - gap: var(--space-1); - min-width: 0; - color: var(--fg-muted); -} -.labelName { - font-size: var(--fs-small); - font-weight: 500; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; +.resizable .message { + white-space: normal; + overflow-wrap: anywhere; } diff --git a/src/features/vcs/LocalHistory.tsx b/src/features/vcs/LocalHistory.tsx index 7399da528..1838c1334 100644 --- a/src/features/vcs/LocalHistory.tsx +++ b/src/features/vcs/LocalHistory.tsx @@ -7,7 +7,7 @@ import { useCallback, useEffect, useRef, useState } from "react"; import type { HistoryEntry } from "@/bindings"; import { call, commands } from "@/platform/ipc"; import { relativePath, useProject } from "@/platform/project"; -import { Button, Icon, List, Spinner, T } from "@/ui"; +import { Button, Icon, List, Spinner, SplitGroup, SplitHandle, SplitPanel, T } from "@/ui"; import { notifications, type EditorInput } from "@/workbench/contributions"; import { DiffEditor } from "./DiffEditor"; import { confirmDialog } from "./dialogs"; @@ -70,6 +70,19 @@ export function LocalHistoryEditor({ input }: { input: EditorInput }) { const anchor = useRef(0); const previous = useRef(0); const pointer = useRef(false); + const container = useRef(null); + const [stacked, setStacked] = useState(false); + + useEffect(() => { + const el = container.current; + if (!el || typeof ResizeObserver === "undefined") return; + const observer = new ResizeObserver(([entry]) => { + const width = entry?.contentRect.width; + if (width) setStacked(width < 620); + }); + observer.observe(el); + return () => observer.disconnect(); + }, []); const load = useCallback(() => { call(commands.historyListDir(path)) @@ -197,9 +210,17 @@ export function LocalHistoryEditor({ input }: { input: EditorInput }) { const revertLabel = current && !isLabel(current) && view?.deleted.has(current.path) ? "Restore" : "Revert"; return ( -
-
+ { pointer.current = e.button === 0 && !!(e.target as Element).closest('[role="option"]'); }} @@ -253,7 +274,7 @@ export function LocalHistoryEditor({ input }: { input: EditorInput }) { setExtra(new Set()); } }} - rowHeight={view.folder ? 52 : 38} + rowHeight={view.folder ? 56 : 44} aria-label="Revisions" className={styles.list} empty={ @@ -261,33 +282,36 @@ export function LocalHistoryEditor({ input }: { input: EditorInput }) { {view.folder ? tx`No local history for this folder yet` : tx`No local history for this path yet`} } - renderItem={(e) => - isLabel(e) ? ( + renderItem={(e) => { + const label = isLabel(e); + const pathText = !label && view.folder ? relativePath(root, e.path) || baseName(e.path) : null; + return ( - {formatTime(e.timestampMs)} - - - {e.label} + + {label && } + + {e.label} + - - ) : ( - - {formatTime(e.timestampMs)} - {view.folder && ( - - {relativePath(root, e.path) || baseName(e.path)} + {pathText && ( + + {pathText} )} - - {e.label} · {formatSize(e.size)} + + {formatTime(e.timestampMs)} + {!label && ` · ${formatSize(e.size)}`} - ) - } + ); + }} /> )} -
-
{detail}
-
+ + + + {detail} + + ); }