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

+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>
)}
/>