mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
fix(editor): make Find Usages result rows easier to scan (#5207)
Find Usages now uses the result tree's font for both line numbers and snippets. Line numbers start at the same indent and take only the width of their digits, with a 4 px gap before the snippet. This brings short line numbers closer to their code and gives the snippet more room on narrow panes.
This commit is contained in:
@@ -163,3 +163,68 @@ for (const theme of ["light", "dark"] as const) {
|
||||
await expect(popup).toBeHidden();
|
||||
});
|
||||
}
|
||||
|
||||
test("Find Usages lines use the tree font and keep line numbers beside the snippet", async ({ workbench: page }) => {
|
||||
await stubDesktop(page);
|
||||
await page.evaluate(async () => {
|
||||
const modulePath = "/src/features/code-insight/usages.ts";
|
||||
const { useUsagesPopup } = await import(modulePath);
|
||||
const path = "/dev/acme-api/src/TaskScheduler.ts";
|
||||
const lines = Array<string>(1001).fill("");
|
||||
const usageLines = [6, 97, 1001];
|
||||
const text = " scheduler.schedule(task);";
|
||||
for (const line of usageLines) lines[line - 1] = text;
|
||||
window.__ipc.handlers.fs_read_text = () => lines.join("\n");
|
||||
useUsagesPopup.setState({
|
||||
open: true,
|
||||
anchor: { x: 100, y: 150 },
|
||||
symbol: "scheduler",
|
||||
loading: false,
|
||||
groups: [
|
||||
{
|
||||
path,
|
||||
usages: usageLines.map((line) => ({
|
||||
path,
|
||||
line: line - 1,
|
||||
col: 2,
|
||||
endCol: 11,
|
||||
text,
|
||||
})),
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
const popup = page.getByRole("dialog", { name: "Usages", exact: true });
|
||||
const popupMatch = popup.getByRole("option").first().locator("mark");
|
||||
const popupFont = await popupMatch.evaluate((node) => getComputedStyle(node).fontFamily);
|
||||
await popup.getByRole("button", { name: /Open in Find Window/ }).click();
|
||||
|
||||
const usages = page.getByRole("region", { name: "Find Usages", exact: true });
|
||||
await expect(usages.locator("mark")).toHaveCount(3);
|
||||
for (const width of [1200, 540]) {
|
||||
await page.setViewportSize({ width, height: 740 });
|
||||
for (const line of ["6", "97", "1001"]) {
|
||||
const row = usages.getByRole("treeitem").filter({ has: page.getByText(line, { exact: true }) });
|
||||
const mark = row.locator("mark");
|
||||
await expect(mark).toHaveText("scheduler");
|
||||
const number = await row.getByText(line, { exact: true }).evaluate((node) => {
|
||||
const text = new Range();
|
||||
text.selectNodeContents(node);
|
||||
const { right } = text.getBoundingClientRect();
|
||||
return { right, font: getComputedStyle(node).fontFamily, size: getComputedStyle(node).fontSize };
|
||||
});
|
||||
const snippet = await mark.evaluate((node) => ({
|
||||
left: node.getBoundingClientRect().left,
|
||||
font: getComputedStyle(node).fontFamily,
|
||||
size: getComputedStyle(node).fontSize,
|
||||
}));
|
||||
const treeFont = await row.evaluate((node) => getComputedStyle(node).fontFamily);
|
||||
expect(snippet.font).toBe(treeFont);
|
||||
expect(number.font).toBe(treeFont);
|
||||
expect(popupFont).not.toBe(treeFont);
|
||||
expect(snippet.size).toBe(number.size);
|
||||
expect(snippet.left - number.right).toBeCloseTo(4, 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -98,13 +98,13 @@
|
||||
flex: none;
|
||||
color: var(--fg-subtle);
|
||||
}
|
||||
.occurrence {
|
||||
gap: var(--space-1);
|
||||
}
|
||||
.line {
|
||||
flex: none;
|
||||
min-width: 3ch;
|
||||
text-align: right;
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--fs-ui);
|
||||
color: var(--fg-line-number);
|
||||
font-variant-numeric: tabular-nums;
|
||||
color: var(--fg-subtle);
|
||||
}
|
||||
.preview {
|
||||
min-width: 0;
|
||||
@@ -114,6 +114,9 @@
|
||||
font-size: var(--fs-code);
|
||||
color: var(--fg);
|
||||
}
|
||||
.occurrence .preview {
|
||||
font: inherit;
|
||||
}
|
||||
.match {
|
||||
background: var(--bg-search-match);
|
||||
color: var(--fg-search-match, inherit);
|
||||
|
||||
@@ -261,7 +261,7 @@ export function UsagesView() {
|
||||
);
|
||||
}
|
||||
return (
|
||||
<span className={clsx(styles.row, excluded.has(n.key) && styles.excluded)}>
|
||||
<span className={clsx(styles.row, styles.occurrence, excluded.has(n.key) && styles.excluded)}>
|
||||
<span className={styles.line}>{n.usage.line + 1}</span>
|
||||
<UsagePreview usage={n.usage} />
|
||||
</span>
|
||||
|
||||
Reference in New Issue
Block a user