fix(search): clarify Recent Locations file captions (#5170)

Recent Locations now shows the filename once, with a symbol breadcrumb or its parent directory beside it. Directory captions distinguish entries with the same filename, and hovering over a caption reveals the full project-relative path.
This commit is contained in:
l0ng-ai
2026-11-22 20:31:00 +08:00
committed by GitHub
parent 3ce4578600
commit 21264641ba
2 changed files with 72 additions and 26 deletions
+39
View File
@@ -93,3 +93,42 @@ test("Recent Locations keeps all snippet lines visible when the editor font grow
await expect(row.getByText("changed", { exact: true })).toBeInViewport({ ratio: 1 });
await expect(filter).toBeFocused();
});
test("Recent Locations shows each file name once with its parent directory", async ({ workbench: page }) => {
await stubDesktop(page);
await page.evaluate(async () => {
const tracking = "/src/features/search/common/tracking.ts";
const { useTracking } = await import(/* @vite-ignore */ tracking);
const now = Date.now();
useTracking.setState({
locations: [
["README.md", "# Shop API"],
["packages/billing/Routes.ts", "registerBillingRoutes();"],
["packages/checkout/Routes.ts", "registerCheckoutRoutes();"],
].map(([path, snippet], index) => ({
path: `/dev/acme-api/${path}`,
line: 0,
col: 0,
changed: false,
time: now - index * 60000,
snippet: [snippet],
snippetStart: 0,
})),
});
});
await openRecent(page, "recentLocations");
const dialog = page.getByRole("dialog", { name: "Recent Locations", exact: true });
const rows = dialog.getByRole("option");
await expect(rows).toHaveCount(3);
await expect(rows.filter({ hasText: "# Shop API" }).getByText("README.md", { exact: true })).toHaveCount(1);
const billing = rows.filter({ hasText: "registerBillingRoutes();" });
const checkout = rows.filter({ hasText: "registerCheckoutRoutes();" });
await expect(billing.getByText("packages/billing", { exact: true })).toBeVisible();
await expect(checkout.getByText("packages/checkout", { exact: true })).toBeVisible();
await expect(checkout.getByTitle("packages/checkout/Routes.ts", { exact: true })).toBeVisible();
await dialog.getByRole("textbox", { name: "Filter recent locations" }).fill("packages/checkout");
await expect(rows).toHaveCount(1);
await expect(rows.first()).toContainText("registerCheckoutRoutes();");
});
+33 -26
View File
@@ -15,6 +15,7 @@ import { call, commands, type OutlineItem } from "@/platform/ipc";
import { monoFontFamily } from "@/platform/fonts";
import { shortcutLabel } from "@/platform/keymap";
import { useProject } from "@/platform/project";
import { isVirtualUri, virtualContainer } from "@/platform/virtualDocs";
import {
Checkbox,
Dialog,
@@ -40,7 +41,7 @@ import {
type ToolWindowContribution,
} from "@/workbench/contributions";
import { highlightTokens, languageForPath, type CodeToken } from "@/editor/lsp/markdown";
import { basename, openInListOrder, openLocation } from "../common/open";
import { basename, openInListOrder, openLocation, relDir } from "../common/open";
import { outlinePathAt } from "../structure/outline";
import { fromNavigationHistory, isDismissed, mergeLocations, type RecentLocation } from "../common/locations";
import { dismissLocation, useTracking } from "../common/tracking";
@@ -688,33 +689,39 @@ function RecentLocationsDialog() {
rowHeight={rowHeight}
aria-label="Recent locations"
empty={<span>{changedOnly ? tx("No changed locations") : tx("No recent locations")}</span>}
renderItem={(l) => (
<div className={styles.location}>
<div className={styles.locationHeader}>
<Icon name={fileIconName(basename(l.rel), l.rel)} size={14} className={styles.icon} />
<HighlightedText
className={clsx(styles.name, styles.locationName)}
text={basename(l.rel)}
indices={l.nameIndices}
tone="strong"
renderItem={(l) => {
const name = basename(l.rel);
const breadcrumb = breadcrumbOf(outlines.get(l.path), l);
const directory = isVirtualUri(l.path) ? virtualContainer(l.path) : relDir(l.rel);
const context = breadcrumb && breadcrumb !== name ? breadcrumb : directory;
return (
<div className={styles.location}>
<div className={styles.locationHeader} title={l.rel}>
<Icon name={fileIconName(name, l.rel)} size={14} className={styles.icon} />
<HighlightedText
className={clsx(styles.name, styles.locationName)}
text={name}
indices={l.nameIndices}
tone="strong"
/>
{context && <span className={styles.dir}>{context}</span>}
{l.changed && (
<span className={styles.changed}>
<T>changed</T>
</span>
)}
<span className={styles.time}>{locationTime(l.time, now)}</span>
</div>
<SnippetCode
path={l.path}
lines={dedent(l.snippet)}
first={l.snippetStart}
caret={l.line}
style={snippetStyle}
/>
<span className={styles.dir}>{breadcrumbOf(outlines.get(l.path), l) || l.rel}</span>
{l.changed && (
<span className={styles.changed}>
<T>changed</T>
</span>
)}
<span className={styles.time}>{locationTime(l.time, now)}</span>
</div>
<SnippetCode
path={l.path}
lines={dedent(l.snippet)}
first={l.snippetStart}
caret={l.line}
style={snippetStyle}
/>
</div>
)}
);
}}
/>
</div>
</Dialog>