From 39068cffb36767667cfd1f7e432370079893545e Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Sun, 22 Nov 2026 21:31:46 +0800 Subject: [PATCH] fix(editor): make Find Usages result rows easier to scan (#5207) Find Usages now uses the result tree's font for both line numbers and snippets. Line numbers start at the same indent and take only the width of their digits, with a 4 px gap before the snippet. This brings short line numbers closer to their code and gives the snippet more room on narrow panes. --- e2e/findUsages-ui.spec.ts | 65 +++++++++++++++++++ .../code-insight/UsagesView.module.css | 13 ++-- src/features/code-insight/UsagesView.tsx | 2 +- 3 files changed, 74 insertions(+), 6 deletions(-) diff --git a/e2e/findUsages-ui.spec.ts b/e2e/findUsages-ui.spec.ts index 6caaf1c3c..2e6fda491 100644 --- a/e2e/findUsages-ui.spec.ts +++ b/e2e/findUsages-ui.spec.ts @@ -163,3 +163,68 @@ for (const theme of ["light", "dark"] as const) { await expect(popup).toBeHidden(); }); } + +test("Find Usages lines use the tree font and keep line numbers beside the snippet", async ({ workbench: page }) => { + await stubDesktop(page); + await page.evaluate(async () => { + const modulePath = "/src/features/code-insight/usages.ts"; + const { useUsagesPopup } = await import(modulePath); + const path = "/dev/acme-api/src/TaskScheduler.ts"; + const lines = Array(1001).fill(""); + const usageLines = [6, 97, 1001]; + const text = " scheduler.schedule(task);"; + for (const line of usageLines) lines[line - 1] = text; + window.__ipc.handlers.fs_read_text = () => lines.join("\n"); + useUsagesPopup.setState({ + open: true, + anchor: { x: 100, y: 150 }, + symbol: "scheduler", + loading: false, + groups: [ + { + path, + usages: usageLines.map((line) => ({ + path, + line: line - 1, + col: 2, + endCol: 11, + text, + })), + }, + ], + }); + }); + + const popup = page.getByRole("dialog", { name: "Usages", exact: true }); + const popupMatch = popup.getByRole("option").first().locator("mark"); + const popupFont = await popupMatch.evaluate((node) => getComputedStyle(node).fontFamily); + await popup.getByRole("button", { name: /Open in Find Window/ }).click(); + + const usages = page.getByRole("region", { name: "Find Usages", exact: true }); + await expect(usages.locator("mark")).toHaveCount(3); + for (const width of [1200, 540]) { + await page.setViewportSize({ width, height: 740 }); + for (const line of ["6", "97", "1001"]) { + const row = usages.getByRole("treeitem").filter({ has: page.getByText(line, { exact: true }) }); + const mark = row.locator("mark"); + await expect(mark).toHaveText("scheduler"); + const number = await row.getByText(line, { exact: true }).evaluate((node) => { + const text = new Range(); + text.selectNodeContents(node); + const { right } = text.getBoundingClientRect(); + return { right, font: getComputedStyle(node).fontFamily, size: getComputedStyle(node).fontSize }; + }); + const snippet = await mark.evaluate((node) => ({ + left: node.getBoundingClientRect().left, + font: getComputedStyle(node).fontFamily, + size: getComputedStyle(node).fontSize, + })); + const treeFont = await row.evaluate((node) => getComputedStyle(node).fontFamily); + expect(snippet.font).toBe(treeFont); + expect(number.font).toBe(treeFont); + expect(popupFont).not.toBe(treeFont); + expect(snippet.size).toBe(number.size); + expect(snippet.left - number.right).toBeCloseTo(4, 0); + } + } +}); diff --git a/src/features/code-insight/UsagesView.module.css b/src/features/code-insight/UsagesView.module.css index 2fd9b6549..76f6be142 100644 --- a/src/features/code-insight/UsagesView.module.css +++ b/src/features/code-insight/UsagesView.module.css @@ -98,13 +98,13 @@ flex: none; color: var(--fg-subtle); } +.occurrence { + gap: var(--space-1); +} .line { flex: none; - min-width: 3ch; - text-align: right; - font-family: var(--font-mono); - font-size: var(--fs-ui); - color: var(--fg-line-number); + font-variant-numeric: tabular-nums; + color: var(--fg-subtle); } .preview { min-width: 0; @@ -114,6 +114,9 @@ font-size: var(--fs-code); color: var(--fg); } +.occurrence .preview { + font: inherit; +} .match { background: var(--bg-search-match); color: var(--fg-search-match, inherit); diff --git a/src/features/code-insight/UsagesView.tsx b/src/features/code-insight/UsagesView.tsx index 4ea7ca88d..3d4e3d8ce 100644 --- a/src/features/code-insight/UsagesView.tsx +++ b/src/features/code-insight/UsagesView.tsx @@ -261,7 +261,7 @@ export function UsagesView() { ); } return ( - + {n.usage.line + 1}