mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
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.
This commit is contained in:
@@ -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");
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
</SplitPanel>
|
||||
<SplitHandle hairline={false} />
|
||||
<SplitPanel id="preview" minSize={96}>
|
||||
<div className={styles.previewHeader}>
|
||||
{selected ? (
|
||||
<span className={styles.previewPath}>
|
||||
<span className={styles.previewName}>{basename(selected.relPath)}</span>
|
||||
{selected.relPath.includes("/") && dirname(selected.relPath)}
|
||||
</span>
|
||||
) : (
|
||||
<span />
|
||||
)}
|
||||
</div>
|
||||
{selected && (
|
||||
<div className={styles.previewHeader} title={selected.relPath}>
|
||||
<span className={styles.previewName}>{basename(selected.relPath)}</span>
|
||||
{previewDirectory && (
|
||||
<span className={styles.previewDirectory} dir="ltr">
|
||||
{previewParentStart > 0 && (
|
||||
<span className={styles.previewSegment}>{previewDirectory.slice(0, previewParentStart)}</span>
|
||||
)}
|
||||
<span className={clsx(styles.previewSegment, styles.previewParent)}>
|
||||
{previewDirectory.slice(previewParentStart)}
|
||||
</span>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<div className={styles.previewBox}>
|
||||
{!stale && previewMode && s.replace && selected ? (
|
||||
<ReplaceDiffPreview
|
||||
|
||||
Reference in New Issue
Block a user