From 828cb271d96856b108a41bb06d86dc5e60574c39 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Sun, 22 Nov 2026 20:28:26 +0800 Subject: [PATCH] fix(search): keep file locations readable in Find in Files (#5145) Give line numbers their own space at the right edge of Find in Files and Replace in Files results. Long file labels can still fit with an ellipsis, and hovering reveals the full relative path. Consecutive hits in the same file use quieter filename text so the line numbers are easier to scan. --- e2e/searchPopupsNarrow.spec.ts | 24 ++++++++++++++----- .../search/find/FindInFiles.module.css | 22 ++++++++++++----- src/features/search/find/FindInFiles.tsx | 22 +++++++++++------ 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/e2e/searchPopupsNarrow.spec.ts b/e2e/searchPopupsNarrow.spec.ts index 3ca17f20c..723bfec04 100644 --- a/e2e/searchPopupsNarrow.spec.ts +++ b/e2e/searchPopupsNarrow.spec.ts @@ -5,6 +5,8 @@ import type { Page } from "@playwright/test"; import { expect, stubDesktop, test } from "./fixtures"; +const LONG_RESULT_PATH = "config/RegionalOrderReconciliationEndpointsForSandboxEnvironments.txt"; + async function run(page: Page, id: string) { await page.evaluate(async (id) => { const actionsModule = "/src/platform/actions.ts"; @@ -15,15 +17,16 @@ async function run(page: Page, id: string) { async function stubFindMatches(page: Page) { await stubDesktop(page); - await page.evaluate(() => { + await page.evaluate((longPath) => { window.__ipc.handlers.search_validate = () => null; window.__ipc.handlers.search_start = (args) => { const send = (event: unknown) => window.__ipc.send(args.onEvent, event); const text = "base=http://localhost:8080"; setTimeout(() => { for (let i = 0; i < 12; i++) { - const relPath = `config/endpoint-${i}.txt`; - const matches = [{ line: 0, text, ranges: [[5, text.length]], textOffset: 0 }]; + const relPath = i === 0 ? longPath : `config/endpoint-${i}.txt`; + const lines = i === 0 ? [12344, 12345] : [0]; + const matches = lines.map((line) => ({ line, text, ranges: [[5, text.length]], textOffset: 0 })); send({ type: "file", file: { path: `/dev/acme-api/${relPath}`, relPath, matches }, @@ -31,12 +34,12 @@ async function stubFindMatches(page: Page) { } send({ type: "done", - summary: { files: 12, matches: 12, limitHit: false, cancelled: false, elapsedMs: 4 }, + summary: { files: 12, matches: 13, limitHit: false, cancelled: false, elapsedMs: 4 }, }); }, 20); return null; }; - }); + }, LONG_RESULT_PATH); } async function expectControlsFit(page: Page) { @@ -74,7 +77,8 @@ test.describe("search popups at the minimum window width", () => { await expect(page.getByRole("dialog").locator("header [aria-live]")).toContainText(/match/); const dialog = page.getByRole("dialog"); const title = dialog.getByText(id === "find.inPath" ? "Find in Files" : "Replace in Files", { exact: true }); - const count = dialog.getByText("12 matches in 12 files", { exact: true }); + const count = dialog.getByText("13 matches in 12 files", { exact: true }); + const line = dialog.getByText("12345", { exact: true }); for (const [width, height] of [ [400, 500], [600, 700], @@ -87,6 +91,14 @@ test.describe("search popups at the minimum window width", () => { expect( await text.evaluate((el) => el.getClientRects().length === 1 && el.scrollWidth <= el.clientWidth), ).toBe(true); + await expect(line).toBeVisible(); + expect( + await line.evaluate( + (el) => el.getBoundingClientRect().right <= el.parentElement!.getBoundingClientRect().right + 0.5, + ), + "the line number fits even when the long filename is elided", + ).toBe(true); + await expect(line.locator("..").getByTitle(LONG_RESULT_PATH)).toBeVisible(); for (const name of ["Search Context", "Pin Window"]) await dialog.getByRole("button", { name, exact: true }).click({ trial: true }); } diff --git a/src/features/search/find/FindInFiles.module.css b/src/features/search/find/FindInFiles.module.css index eafd00a7d..fb6c3c83c 100644 --- a/src/features/search/find/FindInFiles.module.css +++ b/src/features/search/find/FindInFiles.module.css @@ -162,8 +162,8 @@ } .outdated .rowText, .outdated .rowText *, -.outdated .rowFile, -.outdated .rowFile * { +.outdated .rowLocation, +.outdated .rowLocation * { color: var(--fg-faint); } .rowText { @@ -174,18 +174,28 @@ font-family: var(--font-mono); font-weight: var(--fw-code); } -.rowFile { +.rowLocation { flex: none; + display: inline-flex; + align-items: baseline; + gap: var(--space-1-5); max-width: 40%; + color: var(--fg-secondary); + font-size: var(--fs-ui); +} +.rowLocationActive { + color: var(--fg-emphasis); +} +.rowFile { + min-width: 0; overflow: hidden; text-overflow: ellipsis; - color: var(--fg-subtle); } -.rowFileActive { +.rowFileRepeated { color: var(--fg-muted); } .rowLine { - color: var(--fg-faint); + flex: none; font-variant-numeric: tabular-nums; } .previewHeader { diff --git a/src/features/search/find/FindInFiles.tsx b/src/features/search/find/FindInFiles.tsx index b5c25e404..ee4031331 100644 --- a/src/features/search/find/FindInFiles.tsx +++ b/src/features/search/find/FindInFiles.tsx @@ -611,6 +611,7 @@ function FindInFilesDialog() { } renderItem={(r, st) => { const state = s.replace ? groupState(r, marks) : "pending"; + const repeatedFile = !st.active && rows[st.index - 1]?.path === r.path; return ( <> - - {state === "done" && ( - - replaced ·{" "} - - )} - {workspace ? r.relPath : basename(r.relPath)} {r.line + 1} + + + {state === "done" && ( + <> + replaced ·{" "} + + )} + {workspace ? r.relPath : basename(r.relPath)} + {" "} + {r.line + 1} );