mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-25 00:03:08 +00:00
fix(search): keep distinguishing folders visible in search results (#5095)
Search Everywhere shortens long directory paths before the last folder in Files and Classes, so same-named results stay distinguishable; hovering shows the full directory. File names keep their extensions visible when the name fits on the row.
This commit is contained in:
@@ -190,3 +190,71 @@ test("mixed file and action rows align icons and names and keep shortcuts readab
|
||||
expect(keys.x).toBeGreaterThanOrEqual(actionName.x + actionName.width);
|
||||
expect(await shortcut.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
|
||||
});
|
||||
|
||||
test("file and class results keep distinguishing folders visible in a narrow popup", async ({ workbench: page }) => {
|
||||
await page.setViewportSize({ width: 520, height: 608 });
|
||||
await stubDesktop(page);
|
||||
const prefix = "packages/commerce-platform/customer-account-management/src/main/typescript/customer";
|
||||
const folders = ["renewal", "retention"];
|
||||
await page.evaluate(
|
||||
({ prefix, folders }) => {
|
||||
const files = folders.map((folder, index) => {
|
||||
const relPath = `${prefix}/${folder}/OrderService.ts`;
|
||||
return {
|
||||
path: `/dev/acme-api/${relPath}`,
|
||||
relPath,
|
||||
score: 100 - index,
|
||||
indices: Array.from("OrderService", (_, i) => i),
|
||||
};
|
||||
});
|
||||
window.__ipc.handlers.find_files = () => files;
|
||||
window.__ipc.handlers.find_symbols = () =>
|
||||
files.map((file) => ({
|
||||
...file,
|
||||
name: "OrderService",
|
||||
kind: "class",
|
||||
container: null,
|
||||
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 12 } },
|
||||
}));
|
||||
},
|
||||
{ prefix, folders },
|
||||
);
|
||||
|
||||
await doubleShift(page);
|
||||
const dialog = page.getByRole("dialog", { name: "Search Everywhere" });
|
||||
const query = dialog.getByRole("combobox", { name: "Search query" });
|
||||
await query.fill("OrderService");
|
||||
for (const tab of ["Files", "Classes"]) {
|
||||
await dialog.getByRole("tab", { name: tab, exact: true }).click();
|
||||
for (const folder of folders) {
|
||||
const path = `${prefix}/${folder}`;
|
||||
const result = dialog.getByRole("option", { name: new RegExp(folder) });
|
||||
const label = result.getByText(path, { exact: true });
|
||||
await expect(label).toBeVisible();
|
||||
expect(
|
||||
await label.evaluate((el, folder) => {
|
||||
const text = el.lastChild?.nodeType === Node.TEXT_NODE ? el.lastChild : el.lastElementChild?.firstChild;
|
||||
if (!text?.textContent?.endsWith(folder)) return false;
|
||||
const range = document.createRange();
|
||||
range.setStart(text, text.textContent.length - folder.length);
|
||||
range.setEnd(text, text.textContent.length);
|
||||
const label = el.getBoundingClientRect();
|
||||
const clip = text.parentElement!.getBoundingClientRect();
|
||||
const visible = range.getBoundingClientRect();
|
||||
return visible.left >= Math.max(label.left, clip.left) && visible.right <= Math.min(label.right, clip.right);
|
||||
}, folder),
|
||||
).toBe(true);
|
||||
await expect(label).toHaveAttribute("title", path);
|
||||
if (tab === "Files") {
|
||||
const name = result.getByText("OrderService.ts", { exact: true });
|
||||
expect(
|
||||
await name.evaluate((el) => {
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(el);
|
||||
return range.getBoundingClientRect().right <= el.getBoundingClientRect().right;
|
||||
}),
|
||||
).toBe(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -190,6 +190,10 @@
|
||||
white-space: pre;
|
||||
color: var(--fg-strong);
|
||||
}
|
||||
.fileName {
|
||||
flex-shrink: 0;
|
||||
max-width: 100%;
|
||||
}
|
||||
.code {
|
||||
font-family: var(--font-ui);
|
||||
color: var(--fg);
|
||||
@@ -209,6 +213,20 @@
|
||||
white-space: nowrap;
|
||||
color: var(--fg-subtle);
|
||||
}
|
||||
.path {
|
||||
display: inline-flex;
|
||||
}
|
||||
.pathPart {
|
||||
flex: none;
|
||||
min-width: 0;
|
||||
max-width: 100%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.pathPrefix {
|
||||
flex-shrink: 1;
|
||||
}
|
||||
.shortcut {
|
||||
flex: none;
|
||||
color: var(--fg-subtle);
|
||||
|
||||
@@ -858,9 +858,11 @@ function ResultRow({
|
||||
<HighlightedText className={styles.name} text={row.display} indices={row.indices} tone={tone} />
|
||||
{row.container && <span className={styles.location}>{row.container}</span>}
|
||||
</span>
|
||||
<span className={styles.right}>
|
||||
{row.section === "classes" ? relDir(row.rel) || basename(row.rel) : basename(row.rel)}
|
||||
</span>
|
||||
{row.section === "classes" ? (
|
||||
<ResultPath path={relDir(row.rel) || basename(row.rel)} className={styles.right} />
|
||||
) : (
|
||||
<span className={styles.right}>{basename(row.rel)}</span>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
case "action": {
|
||||
@@ -974,6 +976,16 @@ function CodeText({ path, text, indices }: { path: string; text: string; indices
|
||||
);
|
||||
}
|
||||
|
||||
function ResultPath({ path, className }: { path: string; className?: string }) {
|
||||
const separator = Math.max(0, path.lastIndexOf("/"));
|
||||
return (
|
||||
<span className={clsx(className, styles.path)} title={path}>
|
||||
{separator > 0 && <span className={clsx(styles.pathPart, styles.pathPrefix)}>{path.slice(0, separator)}</span>}
|
||||
<span className={styles.pathPart}>{path.slice(separator)}</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function FileRow({
|
||||
path,
|
||||
name,
|
||||
@@ -995,11 +1007,11 @@ function FileRow({
|
||||
<>
|
||||
<Icon name={folder ? "folder" : icon} size={16} className={styles.icon} />
|
||||
<span className={styles.main}>
|
||||
<span className={styles.name} style={deco.color ? { color: deco.color } : undefined}>
|
||||
<span className={clsx(styles.name, styles.fileName)} style={deco.color ? { color: deco.color } : undefined}>
|
||||
<HighlightedText text={name} indices={indices} tone="strong" />
|
||||
{line !== null && <span className={styles.lineSuffix}>:{line + 1}</span>}
|
||||
</span>
|
||||
{dir && <span className={styles.location}>{dir}</span>}
|
||||
{dir && <ResultPath path={dir} className={styles.location} />}
|
||||
</span>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user