From 7febc5270afdbc453ff138fdfdb3aab04423b27b Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Fri, 20 Nov 2026 01:15:28 +0800 Subject: [PATCH] fix(usages): keep results and previews readable in narrow windows --- e2e/codeInsight.spec.ts | 64 +++++++++++++ .../code-insight/UsagesPopup.module.css | 71 +++++++++++---- src/features/code-insight/UsagesPopup.tsx | 90 ++++++++++--------- .../code-insight/UsagesView.module.css | 39 ++++++-- src/features/code-insight/UsagesView.tsx | 72 +++++++++++---- 5 files changed, 252 insertions(+), 84 deletions(-) diff --git a/e2e/codeInsight.spec.ts b/e2e/codeInsight.spec.ts index b222fd9193..c1dab8c826 100644 --- a/e2e/codeInsight.spec.ts +++ b/e2e/codeInsight.spec.ts @@ -345,6 +345,70 @@ test("Find Usages from the editor context menu lists every usage by file and ope ).toHaveAttribute("aria-selected", "true"); }); +test("usage locations and preview stay readable as the available space changes", async ({ workbench: page }) => { + await page.setViewportSize({ width: 1040, height: 760 }); + const editor = await openSample(page); + await page.evaluate( + ({ file, other }) => { + const locations = [ + { path: file, range: { start: { line: 16, col: 8 }, end: { line: 16, col: 15 } } }, + { path: file, range: { start: { line: 20, col: 27 }, end: { line: 20, col: 34 } } }, + { path: other, range: { start: { line: 0, col: 0 }, end: { line: 0, col: 7 } } }, + ]; + window.__ipc.handlers.lsp_references = () => ({ + locations, + classified: [{ location: locations[2], kind: "code", text: "service.submit(order)" }], + incomplete: null, + librariesSkipped: true, + }); + }, + { file: FILE, other: `${ROOT}/domain/checkout/processing/calculations/PaymentProcessingService.kt` }, + ); + await caretAt(editor, page, "val order: Order", "service"); + await page.keyboard.press("Meta+Alt+F7"); + const popup = page.getByRole("dialog", { name: "Usages" }); + const scope = popup.getByRole("button", { name: "Scope" }); + const openWindow = popup.getByRole("button", { name: /^Open in Find Window/ }); + await expect(popup.getByTestId("usage-row")).toHaveCount(3); + await popup.getByRole("button", { name: "Show Preview" }).click(); + const code = popup.getByRole("region", { name: "Preview" }); + await expect(code.locator(".cm-content")).toContainText("service.find(status"); + + await page.setViewportSize({ width: 480, height: 470 }); + const within = async (child: Locator, parent: Locator) => { + const [c, p] = await Promise.all([child.boundingBox(), parent.boundingBox()]); + return ( + !!c && + !!p && + c.x >= p.x - 1 && + c.y >= p.y - 1 && + c.x + c.width <= p.x + p.width + 1 && + c.y + c.height <= p.y + p.height + 1 + ); + }; + await expect.poll(() => within(scope, popup)).toBe(true); + await expect.poll(() => within(openWindow, popup)).toBe(true); + await expect.poll(() => within(code, popup)).toBe(true); + const results = popup.getByRole("listbox", { name: "Usages" }); + await expect.poll(() => within(popup.getByTestId("usage-row").last(), results)).toBe(true); + const firstRow = popup.getByTestId("usage-row").first(); + const file = firstRow.getByText("build.gradle.kts", { exact: true }); + await expect(file).toBeVisible(); + const [filename, snippet] = await Promise.all([file.boundingBox(), firstRow.locator("mark").boundingBox()]); + expect(filename!.x + filename!.width).toBeLessThan(snippet!.x); + await openWindow.click(); + + const tree = page.getByRole("tree", { name: "Usages" }); + const target = tree.getByRole("treeitem", { name: /^17 service\.find\(status/ }); + await target.click(); + const preview = page.getByRole("region", { name: "Preview" }); + await expect(preview).toContainText("service.find(status"); + await expect.poll(async () => (await preview.boundingBox())!.y > (await tree.boundingBox())!.y).toBe(true); + await page.setViewportSize({ width: 1040, height: 760 }); + await expect.poll(async () => (await preview.boundingBox())!.x > (await tree.boundingBox())!.x).toBe(true); + await expect(preview).toContainText("service.find(status"); +}); + test("⇧F6 renames in place and sends the server's edit to be applied", async ({ workbench: page }) => { const editor = await openSample(page); await page.evaluate( diff --git a/src/features/code-insight/UsagesPopup.module.css b/src/features/code-insight/UsagesPopup.module.css index 4e6b6f840e..69b9c26110 100644 --- a/src/features/code-insight/UsagesPopup.module.css +++ b/src/features/code-insight/UsagesPopup.module.css @@ -5,18 +5,27 @@ overflow: hidden; } .header { - height: 26px; flex: none; display: flex; align-items: center; - gap: var(--space-2); - padding: 0 10px; + flex-wrap: wrap; + min-height: var(--h-field); + gap: var(--space-0-5) var(--space-2); + padding: var(--space-0-5) 10px; border-bottom: 1px solid var(--border-popup); - font-size: var(--fs-small); + font-size: var(--fs-ui); color: var(--fg-muted); } +.actions { + display: flex; + align-items: center; + flex-wrap: wrap; + min-width: 0; + gap: var(--space-0-5) var(--space-2); + font-size: var(--fs-small); +} .scope { - flex: none; + max-width: min(100%, 18em); } .searching { @@ -26,23 +35,32 @@ } .title { - flex: 1; + flex: 1 1 160px; + display: flex; + align-items: baseline; + gap: var(--space-1); min-width: 0; + color: var(--fg-emphasis); +} +.titleLabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; - color: var(--fg-emphasis); } .count { + flex: none; + white-space: nowrap; + font-size: var(--fs-small); color: var(--fg-subtle); } .link { - flex: none; + max-width: 100%; border: none; background: none; padding: 0; font: inherit; color: var(--link); + text-align: left; cursor: pointer; } .link:hover { @@ -52,7 +70,6 @@ .body { display: flex; flex-direction: column; - min-height: 24px; padding: 2px 0; box-sizing: content-box; } @@ -60,21 +77,31 @@ flex: 1; } .row { - display: flex; + display: grid; + grid-template-columns: min(34%, 176px) 5ch minmax(0, 1fr); align-items: center; gap: var(--space-2); min-width: 0; width: 100%; } +.file { + display: flex; + align-items: center; + gap: var(--space-1); + min-width: 0; +} .icon { flex: none; color: var(--fg-muted); } -.spacer { - flex: 1; +.fileName { + overflow: hidden; + text-overflow: ellipsis; } -.where { - flex: none; +.line { + overflow: hidden; + text-align: right; + font-variant-numeric: tabular-nums; font-size: var(--fs-small); color: var(--fg-subtle); } @@ -95,12 +122,15 @@ outline: none; } .filter { - flex: none; + max-width: 12ch; font-family: var(--font-mono); color: var(--fg-strong); background: var(--accent-soft); border-radius: var(--radius-small); padding: 0 4px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; } .noMatch { color: var(--danger); @@ -111,8 +141,9 @@ font-size: var(--fs-small); } .preview { - flex: none; - height: 200px; + flex: 0 1 auto; + height: min(164px, 32vh); + min-height: min(64px, 18vh); border-top: 1px solid var(--border-popup); overflow: hidden; } @@ -131,3 +162,9 @@ .previewMatch { background: var(--bg-text-search-result); } + +@media (max-width: 600px) { + .title { + flex-basis: 100%; + } +} diff --git a/src/features/code-insight/UsagesPopup.tsx b/src/features/code-insight/UsagesPopup.tsx index 97e5e3b519..3a5fee8317 100644 --- a/src/features/code-insight/UsagesPopup.tsx +++ b/src/features/code-insight/UsagesPopup.tsx @@ -93,6 +93,7 @@ function UsagesPopupInner() { const [active, setActive] = useState(0); const current = Math.min(active, items.length - 1); const total = usageCount(groups); + const rowCount = Math.max(1, Math.min(14, items.length)); const pick = (u: Usage | undefined) => { if (!u) return; close(); @@ -158,46 +159,48 @@ function UsagesPopupInner() { >
- {symbol ? tx`Usages of ${symbol}` : tx("Usages")}{" "} + {symbol ? tx`Usages of ${symbol}` : tx("Usages")}{" "} {filter || items.length !== total ? tx`${items.length} of ${total} found` : tx`${total} found`} - {scope && ( - - variant="ghost" - aria-label={tx("Scope")} - className={styles.scope} - value={scope} - options={[ - { value: "project", label: tx("Project Files") }, - { value: "libraries", label: tx("Project and Libraries") }, - ]} - onChange={setUsagesPopupScope} +
+ {scope && ( + + variant="ghost" + aria-label={tx("Scope")} + className={styles.scope} + value={scope} + options={[ + { value: "project", label: tx("Project Files") }, + { value: "libraries", label: tx("Project and Libraries") }, + ]} + onChange={setUsagesPopupScope} + /> + )} + {loading && ( + + + + )} + {filter && ( + + {filter} + + )} + e.preventDefault()} + onClick={() => setUsagesPopupPreview(!preview)} /> - )} - {loading && ( - - - - )} - {filter && ( - - {filter} - - )} - e.preventDefault()} - onClick={() => setUsagesPopupPreview(!preview)} - /> - + +
{note && ( @@ -205,7 +208,10 @@ function UsagesPopupInner() { {note} )} -
+
@@ -225,12 +231,14 @@ function UsagesPopupInner() { } renderItem={(u) => (
- - - - - {basename(u.path)}:{u.line + 1} + + + + {basename(u.path)} + + {u.line + 1} +
)} /> diff --git a/src/features/code-insight/UsagesView.module.css b/src/features/code-insight/UsagesView.module.css index 4e8688c11a..2fd9b65491 100644 --- a/src/features/code-insight/UsagesView.module.css +++ b/src/features/code-insight/UsagesView.module.css @@ -25,15 +25,15 @@ background: var(--border); } .summary { - height: 26px; + min-height: 26px; flex: none; display: flex; align-items: center; - gap: var(--space-1-5); - padding: 0 10px; + flex-wrap: wrap; + gap: var(--space-0-5) var(--space-1-5); + padding: var(--space-0-5) 10px; font-size: var(--fs-ui); color: var(--fg-subtle); - white-space: nowrap; } .groupLabel { color: var(--fg); @@ -42,12 +42,13 @@ color: var(--danger); } .link { - flex: none; + max-width: 100%; border: none; background: none; padding: 0; font: inherit; color: var(--link); + text-align: left; cursor: pointer; } .link:hover { @@ -81,9 +82,18 @@ flex: none; } .file { + flex: none; + max-width: 56%; + overflow: hidden; + text-overflow: ellipsis; color: var(--fg); } -.muted, +.directory { + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + color: var(--fg-subtle); +} .count { flex: none; color: var(--fg-subtle); @@ -101,7 +111,7 @@ overflow: hidden; text-overflow: ellipsis; font-family: var(--font-mono); - font-size: var(--fs-ui); + font-size: var(--fs-code); color: var(--fg); } .match { @@ -135,3 +145,18 @@ flex: 1; min-height: 0; } +.splitFrame { + display: flex; + min-width: 0; +} +.sourcePreview { + display: flex; + flex-direction: column; + font-family: var(--font-mono); + font-size: var(--fs-code); + line-height: 1.45; +} +.sourcePreview .sourceText[role="region"] { + font: inherit; + font-weight: var(--fw-code); +} diff --git a/src/features/code-insight/UsagesView.tsx b/src/features/code-insight/UsagesView.tsx index c7d67b1002..5d0c6e95f8 100644 --- a/src/features/code-insight/UsagesView.tsx +++ b/src/features/code-insight/UsagesView.tsx @@ -2,11 +2,13 @@ * "usages" tool window: Find Usages results grouped by file with line * previews, one tab per search (pinnable, as the Find tool window's tabs). */ -import { useCallback, useMemo, useRef, useState, type KeyboardEvent, type ReactNode } from "react"; +import { useCallback, useLayoutEffect, useMemo, useRef, useState, type KeyboardEvent, type ReactNode } from "react"; import clsx from "clsx"; import { create } from "zustand"; import { previewColors, tokenSpans, useLineTokens } from "@/editor/lineTokens"; import { formatMessage, useTx } from "@/platform/i18n"; +import { useEditorPrefs } from "@/platform/editorSettings"; +import { BUNDLED_MONO_FAMILY, monoFontFamily } from "@/platform/fonts"; import { shortcutLabel } from "@/platform/keymap"; import { basename, relativeDir, useProject } from "@/platform/project"; import { maybeEditorService, useOccurrenceNavigator } from "@/workbench/contributions"; @@ -245,8 +247,12 @@ export function UsagesView() { return ( - {basename(path)} - {relativeDir(root, path)} + + {basename(path)} + + + {relativeDir(root, path)} + {n.group.usages.length} {tx(n.group.usages.length === 1 ? "usage" : "usages")} @@ -401,34 +407,62 @@ export function useUsagesHeaderMenu(): MenuItem[] { function UsagesSplit({ preview, children }: { preview: ReactNode; children: ReactNode }) { const show = useUsagesOptions((s) => s.preview); + const frame = useRef(null); + const [stacked, setStacked] = useState(false); + useLayoutEffect(() => { + const el = frame.current; + if (!show || !el) return; + const measure = () => setStacked(el.clientWidth < 580); + measure(); + if (typeof ResizeObserver === "undefined") return; + const observer = new ResizeObserver(measure); + observer.observe(el); + return () => observer.disconnect(); + }, [show]); if (!show) return children; return ( - - - {children} - - - - {preview} - - +
+ + + {children} + + + + {preview} + + +
); } function UsagesPreview({ node }: { node: Node | null }) { const usage = node?.kind === "usage" ? node.usage : node?.kind === "file" ? (node.group.usages[0] ?? null) : null; const search = useUsages(activeUsageSearch); + const settings = useProject((s) => s.settings?.editor); + const { fallbackFont } = useEditorPrefs(); + const family = settings?.fontFamily; + const fontFamily = + (family && family !== BUNDLED_MONO_FAMILY) || fallbackFont.trim() + ? monoFontFamily(family, fallbackFont, "var(--font-mono)") + : undefined; const highlights = useMemo(() => { const group = usage && search?.groups.find((g) => g.path === usage.path); return (group?.usages ?? []).map((u) => ({ line: u.line, ranges: [[u.col, u.endCol] as const] })); }, [usage, search?.groups]); return ( - +
+ +
); }