From c5824771c19bc1eff2df1d5962982b174e50f0f8 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Sun, 22 Nov 2026 20:32:47 +0800 Subject: [PATCH] fix(editor): make workspace refactoring previews easier to scan (#5183) Separate the filename from its directory in workspace refactoring previews. This gives same-named files distinct locations and frees space for rename targets and occurrence counts. Hovering a file or a rename target shows its full path. --- e2e/refactorPreviewLayout.spec.ts | 63 +++++++++++++++++++++++++++++++ src/editor/lsp/Popups.module.css | 45 +++++++++++++--------- src/editor/lsp/Popups.tsx | 47 +++++++++++++---------- 3 files changed, 118 insertions(+), 37 deletions(-) create mode 100644 e2e/refactorPreviewLayout.spec.ts diff --git a/e2e/refactorPreviewLayout.spec.ts b/e2e/refactorPreviewLayout.spec.ts new file mode 100644 index 000000000..e78dbc1ec --- /dev/null +++ b/e2e/refactorPreviewLayout.spec.ts @@ -0,0 +1,63 @@ +import { expect, test } from "./fixtures"; + +test("the workspace refactoring preview separates filenames from directories and keeps outcomes readable", async ({ + workbench: page, +}) => { + await page.setViewportSize({ width: 420, height: 620 }); + await page.evaluate(async () => { + const popupPath = "/src/editor/lsp/popupStore.ts"; + const editPath = "/src/editor/lsp/workspaceEdit.ts"; + const { openPopup } = await import(/* @vite-ignore */ popupPath); + const { summarizeWorkspaceEdit } = await import(/* @vite-ignore */ editPath); + const root = "/dev/acme-api"; + const edit = { + range: { start: { line: 0, col: 0 }, end: { line: 0, col: 9 } }, + new_text: "postInvoice", + }; + openPopup({ + kind: "preview", + title: "Rename 'saveOrder' to 'postInvoice'", + summary: summarizeWorkspaceEdit({ + files: [ + { kind: "edit", path: `${root}/README.md`, edits: [edit] }, + { kind: "edit", path: `${root}/packages/billing/src/Routes.ts`, edits: [edit, edit] }, + { kind: "edit", path: `${root}/packages/checkout/src/Routes.ts`, edits: [edit] }, + { + kind: "rename", + from: `${root}/packages/checkout/src/Invoice.ts`, + to: `${root}/packages/checkout/src/InvoiceReconciliationForInternationalOrders.ts`, + }, + ], + }), + renameThemeClasses: "", + confirmLabel: "Do Refactor", + onConfirm: () => { + document.body.dataset.refactorConfirmed = "true"; + }, + }); + }); + + const dialog = page.getByRole("dialog", { name: "Rename 'saveOrder' to 'postInvoice'" }); + const rows = dialog.getByRole("list", { name: "Changes" }).getByRole("listitem"); + await expect(rows).toHaveCount(4); + await expect(dialog.getByText("4 occurrences in 4 files")).toBeVisible(); + const root = rows.filter({ hasText: "README.md" }); + await expect(root.getByText("README.md", { exact: true })).toHaveCount(1); + + const billing = rows.filter({ hasText: "2 occurrences" }); + await expect(billing.getByText("Routes.ts", { exact: true })).toBeVisible(); + await expect(billing.getByText("packages/billing/src", { exact: true })).toBeVisible(); + await expect(billing.getByTitle("packages/billing/src/Routes.ts", { exact: true })).toBeVisible(); + const checkout = rows.filter({ hasText: "packages/checkout/src" }).filter({ hasText: "Routes.ts" }); + await expect(checkout.getByText("packages/checkout/src", { exact: true })).toBeVisible(); + + const rename = rows.filter({ hasText: "Invoice.ts" }); + const target = rename.getByText("→ InvoiceReconciliationForInternationalOrders.ts", { exact: true }); + await expect(target).toBeVisible(); + await expect(target).toHaveAttribute("title", "packages/checkout/src/InvoiceReconciliationForInternationalOrders.ts"); + expect((await target.boundingBox())!.width).toBeGreaterThan(35); + await expect(dialog.getByRole("button", { name: "Do Refactor", exact: true })).toBeInViewport(); + await dialog.getByRole("button", { name: "Do Refactor", exact: true }).click(); + await expect(dialog).toBeHidden(); + await expect(page.locator("body")).toHaveAttribute("data-refactor-confirmed", "true"); +}); diff --git a/src/editor/lsp/Popups.module.css b/src/editor/lsp/Popups.module.css index 4a23f3c04..41248010c 100644 --- a/src/editor/lsp/Popups.module.css +++ b/src/editor/lsp/Popups.module.css @@ -532,20 +532,6 @@ .renamePreview .previewList { overflow: visible; } -.renamePreview .previewName { - min-width: 0; - max-width: 55%; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; -} -.renamePreview .previewOp { - flex: 0 1 auto; - min-width: 0; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; -} .renamePreview .previewWarning { overflow-wrap: anywhere; } @@ -571,23 +557,46 @@ padding: 0 14px; font-size: var(--fs-ui); } -.previewName { - color: var(--fg-emphasis); +.previewFile { + flex: 1 1 auto; + display: flex; + align-items: baseline; + gap: var(--space-2); + min-width: 0; } -.previewPath { +.previewName, +.previewDirectory, +.previewOp { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; +} +.previewName { + flex: none; + max-inline-size: 100%; + color: var(--fg-emphasis); +} +.previewFile:has(.previewDirectory) .previewName { + max-inline-size: 70%; +} +.previewDirectory { color: var(--fg-subtle); font-size: var(--fs-small); + direction: rtl; } .previewOp, .previewCount { - flex: none; font-size: var(--fs-small); color: var(--fg-muted); } +.previewOp { + max-inline-size: 55%; +} +.previewCount { + flex: none; + font-variant-numeric: tabular-nums; +} .previewWarning { flex: none; diff --git a/src/editor/lsp/Popups.tsx b/src/editor/lsp/Popups.tsx index 6932b353d..00623fa8c 100644 --- a/src/editor/lsp/Popups.tsx +++ b/src/editor/lsp/Popups.tsx @@ -22,7 +22,7 @@ import { selectableText, T, } from "@/ui"; -import { basename, relativePath, useProject } from "@/platform/project"; +import { basename, relativeDir, relativePath, useProject } from "@/platform/project"; import { closePopup, updatePopup, @@ -761,25 +761,34 @@ function PreviewDialog({ popup }: { popup: Extract ) : ( )}