дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-01 06:42:54 +02:00
fix(find): make the Show Usages popup resizable and remember its size
The usages popup had a fixed width and a height set by its row count, so it could not be enlarged on any platform. It now resizes from its right and bottom edges and corner, the list takes the added height, and the size is remembered for the next time it opens. Fixes #6999
Цей коміт міститься в:
1 джерело
485d7bf99d
коміт
840f258e83
4 files changed
+115
-3
No files matched your search
@@ -43,3 +43,48 @@ test("Show Usages distinguishes same-named files without losing the line or snip
|
||||
await expect(checkout.getByTitle("/dev/acme-api/packages/checkout/src/Routes.ts", { exact: true })).toBeVisible();
|
||||
await expect(rows.filter({ hasText: "Worker.ts" }).getByText("src", { exact: true })).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("Show Usages resizes from its corner, the list fills it, and it reopens at that size", async ({
|
||||
workbench: page,
|
||||
}) => {
|
||||
await page.setViewportSize({ width: 1200, height: 800 });
|
||||
const show = () =>
|
||||
page.evaluate(async () => {
|
||||
const { useUsagesPopup } = await import(/* @vite-ignore */ "/src/features/code-insight/usages.ts");
|
||||
const path = "/dev/app/src/Main.ts";
|
||||
useUsagesPopup.setState({
|
||||
open: true,
|
||||
anchor: { x: 30, y: 60 },
|
||||
symbol: "run",
|
||||
groups: [
|
||||
{
|
||||
path,
|
||||
usages: Array.from({ length: 40 }, (_, line) => ({ path, line, col: 0, endCol: 3, text: "run();" })),
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
await show();
|
||||
const popup = page.getByRole("dialog", { name: "Usages", exact: true });
|
||||
const list = popup.getByRole("listbox", { name: "Usages" });
|
||||
const before = (await popup.boundingBox())!;
|
||||
const listBefore = (await list.boundingBox())!;
|
||||
const corner = (await popup.getByRole("separator", { name: "Resize" }).boundingBox())!;
|
||||
await page.mouse.move(corner.x + corner.width / 2, corner.y + corner.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(corner.x + 200, corner.y + 150, { steps: 5 });
|
||||
await page.mouse.up();
|
||||
const after = (await popup.boundingBox())!;
|
||||
expect(after.width).toBeGreaterThan(before.width + 150);
|
||||
expect(after.height).toBeGreaterThan(before.height + 100);
|
||||
// The list, not empty space, takes the added height.
|
||||
expect((await list.boundingBox())!.height).toBeGreaterThan(listBefore.height + 100);
|
||||
await page.screenshot({ path: test.info().outputPath("usages-resized.png") });
|
||||
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(popup).toHaveCount(0);
|
||||
await show();
|
||||
const reopened = (await popup.boundingBox())!;
|
||||
expect(Math.abs(reopened.width - after.width)).toBeLessThanOrEqual(1);
|
||||
expect(Math.abs(reopened.height - after.height)).toBeLessThanOrEqual(1);
|
||||
});
|
||||
@@ -70,9 +70,20 @@
|
||||
.body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: var(--usages-height);
|
||||
min-height: var(--usages-min-height);
|
||||
padding: 2px 0;
|
||||
box-sizing: content-box;
|
||||
}
|
||||
/* Resized: the list takes the height the preview leaves. */
|
||||
.popup[data-resized] .focus {
|
||||
flex: 1 1 0;
|
||||
}
|
||||
.popup[data-resized] .body {
|
||||
flex: 1 1 0;
|
||||
height: auto;
|
||||
min-height: var(--usages-min-height);
|
||||
}
|
||||
.body > * {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* filters), an optional code preview and "Open in Find Window", which moves
|
||||
* the found usages to the Find Usages tool window.
|
||||
*/
|
||||
import { useEffect, useMemo, useRef, useState, type KeyboardEvent } from "react";
|
||||
import { useEffect, useMemo, useRef, useState, type CSSProperties, type KeyboardEvent } from "react";
|
||||
import { create } from "zustand";
|
||||
import clsx from "clsx";
|
||||
import { EditorState, StateEffect, StateField } from "@codemirror/state";
|
||||
@@ -55,6 +55,30 @@ export function setUsagesPopupPreview(preview: boolean) {
|
||||
}
|
||||
}
|
||||
|
||||
const SIZE_KEY = "openidea.usages.popupSize.v1";
|
||||
const MIN_WIDTH = 360;
|
||||
const MIN_HEIGHT = 160;
|
||||
|
||||
/** The size the popup was last resized to, if any (IDEA remembers Show Usages' size). */
|
||||
export function loadUsagesPopupSize(): { w: number; h: number } | null {
|
||||
try {
|
||||
const saved = JSON.parse(localStorage.getItem(SIZE_KEY) ?? "null") as { w?: unknown; h?: unknown } | null;
|
||||
return typeof saved?.w === "number" && typeof saved.h === "number" && Number.isFinite(saved.w + saved.h)
|
||||
? { w: Math.max(MIN_WIDTH, saved.w), h: Math.max(MIN_HEIGHT, saved.h) }
|
||||
: null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function saveUsagesPopupSize(size: { w: number; h: number }) {
|
||||
try {
|
||||
localStorage.setItem(SIZE_KEY, JSON.stringify(size));
|
||||
} catch {
|
||||
// storage unavailable: the size lasts while the popup is open
|
||||
}
|
||||
}
|
||||
|
||||
/** Usages whose file name or line text contains the typed text (case-insensitive). */
|
||||
export function filterUsages(items: readonly Usage[], filter: string): Usage[] {
|
||||
const q = filter.trim().toLowerCase();
|
||||
@@ -102,6 +126,7 @@ function UsagesPopupInner() {
|
||||
[all, filter, accessOptions],
|
||||
);
|
||||
const [active, setActive] = useState(0);
|
||||
const [initialSize] = useState(loadUsagesPopupSize);
|
||||
const current = Math.min(active, items.length - 1);
|
||||
const total = usageCount(groups);
|
||||
const rowCount = Math.max(1, Math.min(14, items.length));
|
||||
@@ -157,7 +182,18 @@ function UsagesPopupInner() {
|
||||
|
||||
const keys = shortcutLabel("find.usages");
|
||||
return (
|
||||
<Popup open anchor={anchor} onClose={close} aria-label="Usages" className={styles.popup}>
|
||||
<Popup
|
||||
open
|
||||
anchor={anchor}
|
||||
onClose={close}
|
||||
aria-label="Usages"
|
||||
className={styles.popup}
|
||||
resizable="both"
|
||||
minWidth={MIN_WIDTH}
|
||||
minHeight={MIN_HEIGHT}
|
||||
initialSize={initialSize}
|
||||
onResized={saveUsagesPopupSize}
|
||||
>
|
||||
<div
|
||||
className={styles.focus}
|
||||
tabIndex={0}
|
||||
@@ -221,7 +257,12 @@ function UsagesPopupInner() {
|
||||
)}
|
||||
<div
|
||||
className={styles.body}
|
||||
style={{ height: rowCount * rowHeight, minHeight: `min(${Math.min(rowCount, 3) * rowHeight}px, 18vh)` }}
|
||||
style={
|
||||
{
|
||||
"--usages-height": `${rowCount * rowHeight}px`,
|
||||
"--usages-min-height": `min(${Math.min(rowCount, 3) * rowHeight}px, 18vh)`,
|
||||
} as CSSProperties
|
||||
}
|
||||
>
|
||||
<List
|
||||
items={items}
|
||||
|
||||
@@ -109,6 +109,21 @@ describe("Show Usages popup", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("is resizable and opens at the size it was left at", () => {
|
||||
localStorage.setItem("openidea.usages.popupSize.v1", JSON.stringify({ w: 900, h: 120 }));
|
||||
try {
|
||||
open();
|
||||
expect(screen.getByRole("separator", { name: "Resize" })).toBeInTheDocument();
|
||||
const popup = screen.getByRole("dialog", { name: "Usages" });
|
||||
expect(popup).toHaveAttribute("data-resized");
|
||||
// Clamped to the minimum height.
|
||||
expect(popup.style.width).toBe("900px");
|
||||
expect(popup.style.height).toBe("160px");
|
||||
} finally {
|
||||
localStorage.removeItem("openidea.usages.popupSize.v1");
|
||||
}
|
||||
});
|
||||
|
||||
it("the preview pane toggles", () => {
|
||||
open();
|
||||
expect(screen.queryByRole("region", { name: "Preview" })).toBeNull();
|
||||
|
||||
Reference in new issue
Заблокувати користувача