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() { >