diff --git a/e2e/diff-navigation.spec.ts b/e2e/diff-navigation.spec.ts index fad40e9f4..63aa177db 100644 --- a/e2e/diff-navigation.spec.ts +++ b/e2e/diff-navigation.spec.ts @@ -1,6 +1,6 @@ import type { EditorView } from "@codemirror/view"; import type { Page } from "@playwright/test"; -import { expect, test } from "./fixtures"; +import { expect, stubDesktop, test } from "./fixtures"; async function openChain(page: Page) { await page.evaluate(async () => { @@ -46,6 +46,70 @@ test("a narrow diff keeps navigation, settings and the difference count visible" await expect(toolbar).toContainText("1 of 1 differences"); }); +test("revision titles keep both filenames in view when the diff divider moves", async ({ workbench: page }) => { + const leftName = "OrderRoutes.ts"; + const rightName = "OrdersRoutes.ts"; + const directory = "services/customer-orders/fulfillment/warehouse-routing/primary"; + await page.setViewportSize({ width: 800, height: 650 }); + await stubDesktop(page); + await page.evaluate( + async ({ directory, leftName, rightName }) => { + const inputPath = "/src/features/vcs/diffInput.ts"; + const layoutPath = "/src/workbench/toolwindows/store.ts"; + const { openDiff } = await import(inputPath); + const { hideAllToolWindows } = await import(layoutPath); + const leftPath = `/dev/acme-api/${directory}/${leftName}`; + const rightPath = `/dev/acme-api/${directory}/${rightName}`; + window.__ipc.handlers.vcs_file_at = (args) => + args.rev === "7b70e02c" ? "export const region = 'east';\r\n" : "export const region = 'west';\n"; + window.__ipc.handlers.vcs_file_mode = () => "100644"; + hideAllToolWindows(); + localStorage.setItem("openidea.vcs.diffOptions", JSON.stringify({ mode: "split", alignChanges: false })); + await openDiff({ + path: rightPath, + left: { type: "rev", rev: "7b70e02c", path: leftPath }, + right: { type: "rev", rev: "a8c5f31d", path: rightPath }, + }); + }, + { directory, leftName, rightName }, + ); + const left = page.getByTitle(/^7b70e02c .*OrderRoutes\.ts$/); + const right = page.getByTitle(/^a8c5f31d .*OrdersRoutes\.ts$/); + const filenamesFit = async () => { + for (const [title, filename] of [ + [left, leftName], + [right, rightName], + ] as const) { + await expect(title).toBeVisible(); + expect(await title.getAttribute("title")).toContain(`${directory}/${filename}`); + const text = title.locator("span").filter({ hasText: filename }).last(); + expect( + await text.evaluate((el, filename) => { + const node = el.firstChild!; + const range = document.createRange(); + range.setStart(node, (node.textContent ?? "").length - filename.length); + range.setEnd(node, (node.textContent ?? "").length); + const bounds = range.getBoundingClientRect(); + const clip = el.getBoundingClientRect(); + return bounds.left >= clip.left - 1 && bounds.right <= clip.right + 1; + }, filename), + `${filename} is visible within its revision label`, + ).toBe(true); + } + }; + await filenamesFit(); + + const divider = page.getByRole("separator", { name: "Resize diff panes" }); + const { x, y, width, height } = (await divider.boundingBox())!; + const leftWidth = (await left.boundingBox())!.width; + await page.mouse.move(x + width / 2, y + height / 2); + await page.mouse.down(); + await page.mouse.move(x + width / 2 - 96, y + height / 2, { steps: 4 }); + await page.mouse.up(); + await expect.poll(async () => (await left.boundingBox())!.width).toBeLessThan(leftWidth - 60); + await filenamesFit(); +}); + test("a medium-width diff keeps its full status beside the viewer tools", async ({ workbench: page }) => { await page.setViewportSize({ width: 490, height: 650 }); await page.evaluate(async () => { diff --git a/src/features/vcs/DiffEditor.module.css b/src/features/vcs/DiffEditor.module.css index ffcbeb3f5..dadb41486 100644 --- a/src/features/vcs/DiffEditor.module.css +++ b/src/features/vcs/DiffEditor.module.css @@ -118,6 +118,22 @@ .sourceLabels .labelFile { font-size: var(--fs-small); } +.labelFile.revisionPath { + display: inline-flex; + color: var(--fg-muted); + font-size: var(--fs-ui); +} +.revisionDirectory, +.revisionFilename { + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; +} +.revisionFilename { + /* Let the directory shrink first, then elide the filename if it still exceeds the path's width. */ + flex: none; + max-width: 100%; +} .badge { padding: 0 5px; border-radius: var(--radius-small); diff --git a/src/features/vcs/DiffEditor.tsx b/src/features/vcs/DiffEditor.tsx index b4281368e..1c170f72e 100644 --- a/src/features/vcs/DiffEditor.tsx +++ b/src/features/vcs/DiffEditor.tsx @@ -111,6 +111,23 @@ import styles from "./DiffEditor.module.css"; /** Commands of the focused diff viewer (diff.* actions, vcs.nextChange / prevChange). */ export { focusedDiffNavigator, type DiffNavigator }; +interface PaneTitle { + label: string; + detail?: string; + revisionPath?: string; +} + +function PaneTitleDetail({ detail, revisionPath }: PaneTitle) { + if (!revisionPath) return detail ? {detail} : null; + const filenameStart = revisionPath.lastIndexOf("/") + 1; + return ( + + {filenameStart > 0 && {revisionPath.slice(0, filenameStart)}} + {revisionPath.slice(filenameStart)} + + ); +} + interface Views { /** The right / unified editor (chunks live here). */ b: EditorView; @@ -1371,7 +1388,7 @@ export function DiffEditor({ const canStage = editableB && isWorktree(right) && left.type === "rev" && !!useVcs.getState().root; const hasSource = !!source; - const paneTitle = (s: DiffSide): { label: string; detail?: string } => { + const paneTitle = (s: DiffSide): PaneTitle => { if (s.type === "worktree" || s.type === "text") return { label: sideLabel(s), detail: s.labelDetail }; if (s.type !== "rev") return { label: sideLabel(s) }; const file = s.path ?? path; @@ -1379,13 +1396,13 @@ export function DiffEditor({ const commit = !s.label && s.rev === "HEAD" && root ? heads[root]?.headCommit : null; return { label: commit ? commit.slice(0, 8) : sideLabel(s), - detail: root && file.startsWith(`${root}/`) ? file.slice(root.length + 1) : file, + revisionPath: root && file.startsWith(`${root}/`) ? file.slice(root.length + 1) : file, }; }; const titleA = paneTitle(left); const titleB = paneTitle(right); - const captionA = [titleA.label, titleA.detail].filter(Boolean).join(" "); - const captionB = [titleB.label, titleB.detail].filter(Boolean).join(" "); + const captionA = [titleA.label, titleA.revisionPath ?? titleA.detail].filter(Boolean).join(" "); + const captionB = [titleB.label, titleB.revisionPath ?? titleB.detail].filter(Boolean).join(" "); const sourceLabels = "labelDetail" in left || "labelDetail" in right; const labels = clsx(styles.labels, sourceLabels && styles.sourceLabels); @@ -1591,7 +1608,7 @@ export function DiffEditor({