fix(search): improve recent file and location layouts (#4548)

Recent Files keeps directories beside file names and gives the list and filter more room in narrow windows. Recent Locations snippets follow the editor font and line spacing, and long file names leave room for the change label and timestamp.
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-11-20 00:22:22 +08:00
1 джерело 479123dcf3
коміт 977ce62bf0
3 files changed
+172 -16

No files matched your search

+94
Переглянути файл
@@ -0,0 +1,94 @@
import type { Page } from "@playwright/test";
import { expect, stubDesktop, test } from "./fixtures";
async function openRecent(page: Page, kind: "recentFiles" | "recentLocations") {
await page.evaluate(async (id) => {
const actions = "/src/platform/actions.ts";
void (await import(/* @vite-ignore */ actions)).executeAction(`navigate.${id}`);
}, kind);
}
test("Recent Files keeps directories beside names and leaves room for files in a narrow window", async ({
workbench: page,
}) => {
await stubDesktop(page);
await page.evaluate(() => {
window.__ipc.handlers.recent_files = () => ["/dev/acme-api/src/orders/InvoiceService.ts"];
});
await openRecent(page, "recentFiles");
const dialog = page.getByRole("dialog", { name: "Recent Files", exact: true });
const files = dialog.getByRole("listbox", { name: "Recent files" });
const row = files.getByRole("option").first();
const name = row.getByText("InvoiceService.ts", { exact: true });
const directory = row.getByText("src/orders", { exact: true });
await expect(name).toBeVisible();
const nameRight = await name.evaluate((el) => el.getBoundingClientRect().right);
const dirLeft = (await directory.boundingBox())!.x;
expect(dirLeft - nameRight).toBeLessThanOrEqual(8);
await page.setViewportSize({ width: 400, height: 500 });
expect((await files.boundingBox())!.width).toBeGreaterThan(200);
expect((await dialog.getByRole("textbox", { name: "Filter recent files" }).boundingBox())!.width).toBeGreaterThan(
200,
);
await expect.poll(() => directory.evaluate((el) => el.getBoundingClientRect().width)).toBeGreaterThan(20);
await expect(dialog.getByRole("button", { name: /Recent Locations/ })).toBeVisible();
const footer = dialog.locator("footer");
await expect(footer).toBeInViewport({ ratio: 1 });
expect(
await dialog.locator("[data-dialog-body]").evaluate((el) => el.scrollHeight - el.clientHeight),
).toBeLessThanOrEqual(1);
});
test("Recent Locations keeps all snippet lines visible when the editor font grows", 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);
useTracking.setState({
locations: [
{
path: "/dev/acme-api/src/orders/CalculateOutstandingInvoicesForTheMonthlyReconciliation.ts",
line: 41,
col: 4,
changed: true,
time: Date.now(),
snippet: ["const invoices = await repository.openInvoices();", "return sum(invoices);", "}"],
snippetStart: 40,
},
],
});
});
await openRecent(page, "recentLocations");
const dialog = page.getByRole("dialog", { name: "Recent Locations", exact: true });
const row = dialog.getByRole("option").first();
const code = row.locator("pre");
await expect(code).toContainText("return sum(invoices);");
await page.evaluate(async () => {
const project = "/src/platform/project.ts";
const { useProject } = await import(/* @vite-ignore */ project);
const { settings } = useProject.getState();
useProject.setState({
settings: {
...settings,
editor: {
...settings?.editor,
fontFamily: "Fira Code",
fallbackFont: "Maple Mono NF CN",
fontSize: 19,
lineHeight: 30,
},
},
});
});
await expect(code).toHaveCSS("font-size", "19px");
await expect(code).toHaveCSS("line-height", "30px");
await expect(code).toHaveCSS("font-family", /"Fira Code".*"Maple Mono NF CN"/);
expect((await code.boundingBox())!.height).toBe(90);
await page.setViewportSize({ width: 400, height: 500 });
const filter = dialog.getByRole("textbox", { name: "Filter recent locations" });
expect((await filter.boundingBox())!.width).toBeGreaterThan(200);
await expect(row.getByText("changed", { exact: true })).toBeInViewport({ ratio: 1 });
await expect(filter).toBeFocused();
});
+45 -7
Переглянути файл
@@ -1,8 +1,14 @@
.dialog {
--rp-bg-chrome: var(--bg-frame, var(--bg-app));
container-type: inline-size;
max-height: 80vh;
background: var(--bg-popup, var(--bg-elev));
}
.dialog > :global([data-dialog-body]) {
display: flex;
flex-direction: column;
overflow: hidden;
}
.header {
flex: none;
display: flex;
@@ -78,7 +84,7 @@
}
.tools {
flex: none;
width: 230px;
width: clamp(140px, 32%, 230px);
display: flex;
flex-direction: column;
padding: 6px 0 4px;
@@ -132,9 +138,13 @@
.current {
font-style: italic;
}
.fileName,
.locationName {
flex: 0 1 auto;
}
.dir {
flex: none;
max-width: 50%;
flex: 0 1000 auto;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
color: var(--fg-subtle);
@@ -162,23 +172,23 @@
}
.locationHeader {
display: flex;
flex: none;
align-items: center;
gap: var(--space-2);
height: 20px;
}
.locationName {
flex: none;
font-weight: 600;
}
.changed {
flex: none;
margin-left: auto;
color: var(--vcs-modified);
font-size: var(--fs-small);
}
.snippet {
margin: 0;
font-family: var(--font-mono);
font-size: var(--fs-small);
line-height: 16px;
font-size: var(--fs-code);
color: var(--fg-muted);
overflow: hidden;
}
@@ -233,3 +243,31 @@
overflow: hidden;
text-overflow: ellipsis;
}
@container (max-width: 480px) {
.header {
height: auto;
flex-wrap: wrap;
gap: var(--space-2);
padding: var(--space-2) var(--space-3);
}
.speed {
order: 1;
flex-basis: 100%;
background: var(--bg-input);
box-shadow: inset 0 0 0 1px var(--border);
}
.speed .filterIcon {
visibility: visible;
}
.speed .filter {
caret-color: var(--fg-strong);
}
.hint,
.tools .shortcut {
display: none;
}
.locationsLink {
margin-inline: var(--space-1);
}
}
+33 -9
Переглянути файл
@@ -1,9 +1,18 @@
import { useFilePresentation } from "@/ui/filePresentation";
import { useEffect, useMemo, useRef, useState, type KeyboardEvent, type MouseEvent as ReactMouseEvent } from "react";
import {
useEffect,
useMemo,
useRef,
useState,
type CSSProperties,
type KeyboardEvent,
type MouseEvent as ReactMouseEvent,
} from "react";
import { flushSync } from "react-dom";
import clsx from "clsx";
import { editorsFor, getNavigationHistory } from "@/editor/api";
import { call, commands, type OutlineItem } from "@/platform/ipc";
import { monoFontFamily } from "@/platform/fonts";
import { shortcutLabel } from "@/platform/keymap";
import { useProject } from "@/platform/project";
import {
@@ -451,12 +460,12 @@ function RecentFileRow({ item, current }: { item: RecentFileItem; current: boole
<>
<Icon name={item.editor?.icon ?? icon} size={16} className={styles.icon} />
<span
className={clsx(styles.name, current && styles.current)}
className={clsx(styles.name, styles.fileName, current && styles.current)}
style={deco.color ? { color: deco.color } : undefined}
>
<HighlightedText text={item.name} indices={item.indices} tone="strong" />
</span>
<span className={styles.dir}>{item.dir}</span>
{item.dir && <span className={styles.dir}>{item.dir}</span>}
</>
);
}
@@ -489,8 +498,6 @@ function withSnippets(list: RecentLocation[], recorded: readonly RecentLocation[
});
}
const LOCATION_ROW = 78;
function breadcrumbOf(outline: readonly OutlineItem[] | undefined, l: RecentLocation): string {
return outline ? locationBreadcrumb(outlinePathAt(outline, { line: l.line, col: l.col })) : "";
}
@@ -528,11 +535,13 @@ function SnippetCode({
lines,
first,
caret,
style,
}: {
path: string;
lines: readonly string[];
first: number;
caret: number;
style: CSSProperties;
}) {
const language = useMemo(() => languageForPath(path), [path]);
const text = lines.join("\n");
@@ -553,7 +562,7 @@ function SnippetCode({
}, [key, language, text, tokens]);
const segments = useMemo(() => lineSegments(lines, tokens ?? []), [lines, tokens]);
return (
<pre className={styles.snippet}>
<pre className={styles.snippet} style={style}>
{segments.map((segs, i) => (
<div key={i} className={clsx(styles.snippetLine, first + i === caret && styles.caretLine)}>
<span className={styles.lineNo}>{first + i + 1}</span>
@@ -581,6 +590,14 @@ function RecentLocationsDialog() {
const recorded = useTracking((s) => s.locations);
const dismissed = useTracking((s) => s.dismissed);
const root = useProject((s) => s.project?.root ?? null);
const editor = useProject((s) => s.settings?.editor);
const lineHeight = Math.max(editor?.fontSize ?? 13, editor?.lineHeight ?? 22);
const rowHeight = 30 + 3 * lineHeight;
const snippetStyle: CSSProperties = {
fontFamily: monoFontFamily(editor?.fontFamily ?? undefined, editor?.fallbackFont, "var(--font-mono)"),
fontSize: editor?.fontSize ?? undefined,
lineHeight: `${lineHeight}px`,
};
const [query, setQuery] = useState("");
const [index, setIndex] = useState(0);
const inputRef = useRef<HTMLInputElement>(null);
@@ -659,6 +676,7 @@ function RecentLocationsDialog() {
</header>
<div className={styles.locations}>
<List
key={rowHeight}
items={items}
getKey={(l) => `${l.path}:${l.line}:${l.time}`}
activeIndex={active}
@@ -669,7 +687,7 @@ function RecentLocationsDialog() {
open(l, e.shiftKey);
}}
focusable={false}
rowHeight={LOCATION_ROW}
rowHeight={rowHeight}
aria-label="Recent locations"
empty={<span>{changedOnly ? tx("No changed locations") : tx("No recent locations")}</span>}
renderItem={(l) => (
@@ -677,7 +695,7 @@ function RecentLocationsDialog() {
<div className={styles.locationHeader}>
<Icon name={fileIconName(basename(l.rel), l.rel)} size={14} className={styles.icon} />
<HighlightedText
className={styles.locationName}
className={clsx(styles.name, styles.locationName)}
text={basename(l.rel)}
indices={l.nameIndices}
tone="strong"
@@ -690,7 +708,13 @@ function RecentLocationsDialog() {
)}
<span className={styles.time}>{locationTime(l.time, now)}</span>
</div>
<SnippetCode path={l.path} lines={dedent(l.snippet)} first={l.snippetStart} caret={l.line} />
<SnippetCode
path={l.path}
lines={dedent(l.snippet)}
first={l.snippetStart}
caret={l.line}
style={snippetStyle}
/>
</div>
)}
/>