From ff7bfcaf1d8f0ccb16a1d7189e42907b92eadc54 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Mon, 23 Nov 2026 09:15:20 +0800 Subject: [PATCH] fix(search): keep file context visible in Find previews (#5275) The source preview in Find in Files and Replace in Files keeps the filename prominent and leaves the end of its containing path visible. The middle of a long directory shortens to fit, and hovering over the caption reveals the full project-relative path. --- e2e/searchPopupsNarrow.spec.ts | 30 +++++++++++++++++-- .../search/find/FindInFiles.module.css | 25 +++++++++++----- src/features/search/find/FindInFiles.tsx | 27 ++++++++++------- 3 files changed, 62 insertions(+), 20 deletions(-) diff --git a/e2e/searchPopupsNarrow.spec.ts b/e2e/searchPopupsNarrow.spec.ts index e869ecbad..7ac1c5ab6 100644 --- a/e2e/searchPopupsNarrow.spec.ts +++ b/e2e/searchPopupsNarrow.spec.ts @@ -15,7 +15,7 @@ async function run(page: Page, id: string) { }, id); } -async function stubFindMatches(page: Page) { +async function stubFindMatches(page: Page, firstPath = LONG_RESULT_PATH) { await stubDesktop(page); await page.evaluate((longPath) => { window.__ipc.handlers.search_validate = () => null; @@ -39,7 +39,7 @@ async function stubFindMatches(page: Page) { }, 20); return null; }; - }, LONG_RESULT_PATH); + }, firstPath); } async function expectControlsFit(page: Page) { @@ -205,3 +205,29 @@ test("Find in Files prioritizes the preview and remembers an adjusted split", as await expect(handle).toBeAttached(); await expect.poll(resultsShare).toBeCloseTo(adjusted, 2); }); + +test("Find in Files keeps the file and its parent folder visible in the preview caption", async ({ + workbench: page, +}) => { + await page.setViewportSize({ width: 400, height: 570 }); + const prefix = "config/generated/regional-integrations/sandbox/development/notifications"; + const name = "RegionalLedgerSettings.txt"; + const path = `${prefix}/runtime/${name}`; + await stubFindMatches(page, path); + await run(page, "find.inPath"); + const dialog = page.getByRole("dialog", { name: "Find in Files" }); + const search = dialog.getByPlaceholder("Search"); + await search.fill("http://localhost:8080"); + const preview = dialog.locator("[data-panel][id=preview]"); + const caption = preview.getByTitle(path, { exact: true }); + const folder = caption.getByText("/runtime", { exact: true }); + const beginning = caption.getByText(prefix, { exact: true }); + await expect(caption.getByText(name, { exact: true })).toBeInViewport({ ratio: 1 }); + await expect(folder).toBeInViewport({ ratio: 1 }); + await expect(folder).toHaveCSS("font-size", "13px"); + expect(await beginning.evaluate((el) => el.scrollWidth > el.clientWidth)).toBe(true); + expect(await folder.evaluate((el) => el.scrollWidth <= el.clientWidth)).toBe(true); + await search.press("ArrowDown"); + await search.press("ArrowDown"); + await expect(preview.getByTitle("config/endpoint-1.txt", { exact: true })).toContainText("endpoint-1.txt"); +}); diff --git a/src/features/search/find/FindInFiles.module.css b/src/features/search/find/FindInFiles.module.css index 7a0491c59..feb89ba4a 100644 --- a/src/features/search/find/FindInFiles.module.css +++ b/src/features/search/find/FindInFiles.module.css @@ -201,23 +201,32 @@ .previewHeader { flex: none; display: flex; - align-items: center; - justify-content: space-between; - gap: 10px; - height: 36px; - padding: 0 20px; + align-items: baseline; + gap: var(--space-1); + padding: 10px 20px var(--space-1-5); border-top: 1px solid var(--border-popup); color: var(--fg-subtle); + font-size: var(--fs-ui); + line-height: 1.25; + white-space: nowrap; } -.previewPath { +.previewDirectory { + display: flex; min-width: 0; +} +.previewName, +.previewSegment { + min-width: 0; + max-width: 100%; overflow: hidden; text-overflow: ellipsis; - white-space: nowrap; +} +.previewName, +.previewParent { + flex: none; } .previewName { color: var(--fg-strong); - margin-right: 8px; } .previewBox { flex: 1; diff --git a/src/features/search/find/FindInFiles.tsx b/src/features/search/find/FindInFiles.tsx index bd7318ede..67590918c 100644 --- a/src/features/search/find/FindInFiles.tsx +++ b/src/features/search/find/FindInFiles.tsx @@ -282,6 +282,8 @@ function FindInFilesDialog() { const rows = useMemo(() => matchRows(state.files), [state.files]); const active = rows.length ? Math.min(sel.lead, rows.length - 1) : -1; const selected = active >= 0 ? rows[active] : undefined; + const previewDirectory = selected?.relPath.includes("/") ? dirname(selected.relPath) : ""; + const previewParentStart = Math.max(0, previewDirectory.lastIndexOf("/")); const chosen = useMemo(() => selectedRows(rows, sel), [rows, sel]); const fileHighlights = useMemo(() => { if (stale || !selected) return []; @@ -864,16 +866,21 @@ function FindInFilesDialog() { -
- {selected ? ( - - {basename(selected.relPath)} - {selected.relPath.includes("/") && dirname(selected.relPath)} - - ) : ( - - )} -
+ {selected && ( +
+ {basename(selected.relPath)} + {previewDirectory && ( + + {previewParentStart > 0 && ( + {previewDirectory.slice(0, previewParentStart)} + )} + + {previewDirectory.slice(previewParentStart)} + + + )} +
+ )}
{!stale && previewMode && s.replace && selected ? (