feat(search): make Search Everywhere resizable from all edges and corners (#7373)

Search Everywhere opened at a fixed 700 px width with its height capped at 600 px, clipping long paths, containers and previews on wide monitors. Dialog's resizable="both" now resizes from all eight edges and corners (the opposite edge stays put), not only the bottom-right grip, and Search Everywhere uses it with a remembered size (openidea.search.everywhereSize.v1, clamped to its minimum). The other resizable dialogs get the edge handles too.

Covered by Dialog and Search Everywhere tests.

Co-authored-by: elfadl <[email protected]>
Цей коміт міститься в:
Kamal ElFadlтаelfadl authored and GitHub committed 2026-12-02 13:04:52 +08:00
1 джерело 54ce048ec9
коміт fdc4df4752
8 files changed
+408 -51

No files matched your search

+44
Переглянути файл
@@ -87,6 +87,7 @@ beforeEach(() => {
useFindPopup.setState({ caseSensitive: false, wholeWord: false, isRegex: false });
localStorage.removeItem(TEXT_SEARCH_OPTIONS_KEY);
localStorage.removeItem(RECENT_FILES_SIZE_KEY);
localStorage.removeItem("openidea.search.everywhereSize.v1");
vi.mocked(openLocation).mockClear();
});
@@ -1027,3 +1028,46 @@ it("restarts a custom query restored before its debounce expires", async () => {
expect(screen.getByText("Fresh route")).toBeVisible();
act(remove);
});
describe("Search Everywhere resize", () => {
it("is resizable, persists its size globally, and keeps that size when empty", async () => {
render(<SearchEverywhereOverlay />);
act(() => showSearchEverywhere("all"));
await tick();
const dialog = screen.getByRole("dialog", { name: "Search Everywhere" });
expect(dialog).not.toHaveAttribute("data-resized");
expect(within(dialog).getByRole("separator", { name: "Resize" })).toBeInTheDocument();
fireEvent.pointerDown(within(dialog).getByRole("separator", { name: "Resize" }), {
button: 0,
clientX: 0,
clientY: 0,
});
fireEvent.pointerMove(window, { buttons: 1, clientX: 820, clientY: 520 });
fireEvent.pointerUp(window);
expect(dialog).toHaveAttribute("data-resized");
expect([dialog.style.width, dialog.style.height]).toEqual(["820px", "520px"]);
expect(JSON.parse(localStorage.getItem("openidea.search.everywhereSize.v1")!)).toEqual({ w: 820, h: 520 });
act(() => hideSearchEverywhere());
act(() => showSearchEverywhere("classes", { query: "" }));
await tick();
const reopened = screen.getByRole("dialog", { name: "Search Everywhere" });
expect(reopened).toHaveAttribute("data-resized");
expect([reopened.style.width, reopened.style.height]).toEqual(["820px", "520px"]);
});
it("clamps stored sizes to the minimum dimensions", async () => {
localStorage.setItem("openidea.search.everywhereSize.v1", JSON.stringify({ w: 200, h: 100 }));
render(<SearchEverywhereOverlay />);
act(() => showSearchEverywhere("classes", { query: "" }));
await tick();
const dialog = screen.getByRole("dialog", { name: "Search Everywhere" });
expect(dialog).toHaveAttribute("data-resized");
expect([dialog.style.width, dialog.style.height]).toEqual(["480px", "240px"]);
});
});
+16 -1
Переглянути файл
@@ -147,11 +147,26 @@
/* `auto`, not `1`: without the preview `.content` has no definite height, and a 0% basis there
collapses the list in the system WebKit of macOS 15 instead of using its inline height. */
flex: 1 1 auto;
height: var(--se-list-height, auto);
min-height: 0;
display: flex;
flex-direction: column;
padding: 0 0 8px;
}
.dialog[data-resized] {
max-height: calc(100vh - 24px);
}
.dialog[data-resized] .content {
flex: 1 1 0%;
min-height: 0;
}
.dialog[data-resized] .withPreview {
height: auto;
}
.dialog[data-resized] .results {
flex: 1 1 0%;
height: auto;
}
.list {
flex: 1;
min-height: 0;
@@ -296,7 +311,7 @@
align-items: center;
gap: 14px;
height: 30px;
padding: 0 12px;
padding: 0 20px 0 12px;
background: var(--se-bg-header);
border-top: 1px solid var(--border-popup);
color: var(--fg-subtle);
+12 -2
Переглянути файл
@@ -2,7 +2,7 @@ import { writeClipboardText } from "@/platform/clipboard";
import { onSearchCategoriesChanged, onEndpointsChanged } from "@/workbench/contributions";
import { useFilePresentation } from "@/ui/filePresentation";
import { useRowHeight } from "@/ui/density";
import { useEffect, useMemo, useRef, useState, type KeyboardEvent, type MouseEvent } from "react";
import { useEffect, useMemo, useRef, useState, type CSSProperties, type KeyboardEvent, type MouseEvent } from "react";
import clsx from "clsx";
import { actionToggled, executeAction, executeActionFrom, getAction } from "@/platform/actions";
import { onIdeEvent, type ProjectFileSet } from "@/platform/ipc";
@@ -66,10 +66,14 @@ import {
type SectionId,
} from "./model";
import {
SE_MIN_HEIGHT,
SE_MIN_WIDTH,
hideSearchEverywhere,
loadSearchEverywhereSize,
onSearchEverywhereQuery,
pushRecentAction,
pushSearchHistory,
saveSearchEverywhereSize,
searchHistory,
selectSearchEverywhereTab,
setIncludeNonProject,
@@ -134,6 +138,7 @@ const INITIAL_SELECTION: Selection = { key: null, anchorKey: null, lead: -1, anc
function SearchEverywhereDialog() {
const tx = useTx();
const rowHeight = useRowHeight(ROW);
const [initialSize] = useState(loadSearchEverywhereSize);
const tab = useSearchEverywhere((s) => s.tab);
const hint = hintFor(tab, tx);
const [tabs, setTabs] = useState(searchTabs);
@@ -586,7 +591,7 @@ function SearchEverywhereDialog() {
<div
ref={listRef}
className={styles.results}
style={{ height: rows.length && !preview ? listHeight + 8 : undefined }}
style={rows.length && !preview ? ({ "--se-list-height": `${listHeight + 8}px` } as CSSProperties) : undefined}
>
{rows.length > 0 && (
<List<SeRow>
@@ -643,6 +648,11 @@ function SearchEverywhereDialog() {
open
onClose={close}
width={700}
resizable="both"
minWidth={SE_MIN_WIDTH}
minHeight={SE_MIN_HEIGHT}
initialSize={initialSize}
onResized={saveSearchEverywhereSize}
position="top"
transparentBackdrop
aria-label={tx("Search Everywhere")}
+14
Переглянути файл
@@ -31,6 +31,20 @@ interface SeState {
const PREVIEW_KEY = "openidea.search.everywherePreview.v1";
const FILTERS_KEY = "openidea.search.everywhereFilters.v1";
const SIZE_KEY = "openidea.search.everywhereSize.v1";
export const SE_MIN_WIDTH = 480;
export const SE_MIN_HEIGHT = 240;
export function loadSearchEverywhereSize(): { w: number; h: number } | null {
const v = loadJson<{ w?: unknown; h?: unknown } | null>(SIZE_KEY, null);
return typeof v?.w === "number" && typeof v.h === "number" && Number.isFinite(v.w + v.h) && v.w > 0 && v.h > 0
? { w: Math.max(SE_MIN_WIDTH, v.w), h: Math.max(SE_MIN_HEIGHT, v.h) }
: null;
}
export function saveSearchEverywhereSize(size: { w: number; h: number }) {
saveJson(SIZE_KEY, size);
}
export const useSearchEverywhere = create<SeState>(() => ({
open: false,
+55
Переглянути файл
@@ -49,6 +49,7 @@
position: absolute;
right: 0;
bottom: 0;
z-index: 2;
width: 16px;
height: 16px;
cursor: nwse-resize;
@@ -69,6 +70,60 @@
.resizeGrip:hover {
opacity: 1;
}
.resizeEdge {
position: absolute;
z-index: 2;
touch-action: none;
}
.resizeN {
top: 0;
left: 10px;
right: 10px;
height: 4px;
cursor: ns-resize;
}
.resizeS {
bottom: 0;
left: 10px;
right: 16px;
height: 4px;
cursor: ns-resize;
}
.resizeW {
left: 0;
top: 10px;
bottom: 10px;
width: 4px;
cursor: ew-resize;
}
.resizeE {
right: 0;
top: 10px;
bottom: 16px;
width: 4px;
cursor: ew-resize;
}
.resizeNW {
top: 0;
left: 0;
width: 10px;
height: 10px;
cursor: nwse-resize;
}
.resizeNE {
top: 0;
right: 0;
width: 10px;
height: 10px;
cursor: nesw-resize;
}
.resizeSW {
bottom: 0;
left: 0;
width: 10px;
height: 10px;
cursor: nesw-resize;
}
/* Title bar (drag handle). macOS: traffic lights then the title; else title + close. */
.titleBar {
+130
Переглянути файл
@@ -176,14 +176,144 @@ describe("Dialog chrome", () => {
</Dialog>,
);
const dialog = screen.getByRole("dialog");
expect(dialog).not.toHaveAttribute("data-resized");
expect(dialog.style.maxHeight).toBe("min(720px, 100%)");
fireEvent.pointerDown(screen.getByRole("separator", { name: "Resize" }), { button: 0, clientX: 0, clientY: 0 });
fireEvent.pointerMove(window, { buttons: 1, clientX: 500, clientY: 800 });
fireEvent.pointerUp(window);
expect(dialog).toHaveAttribute("data-resized");
expect(dialog.style.maxHeight).toBe("");
expect(dialog.style.height).not.toBe("");
});
it("resizes from the left edge without shifting the right edge or changing height", () => {
const onResized = vi.fn();
render(
<Dialog
open
onClose={() => {}}
position="top"
aria-label="Search Everywhere"
width={400}
resizable="both"
minWidth={200}
minHeight={100}
onResized={onResized}
>
<div>rows</div>
</Dialog>,
);
const dialog = screen.getByRole("dialog");
vi.spyOn(dialog, "getBoundingClientRect").mockReturnValue({
x: 200,
y: 50,
left: 200,
top: 50,
right: 600,
bottom: 350,
width: 400,
height: 300,
toJSON: () => ({}),
});
const west = dialog.querySelector('[data-resize="w"]') as HTMLElement;
fireEvent.pointerDown(west, { button: 0, clientX: 200, clientY: 150 });
fireEvent.pointerMove(window, { buttons: 1, clientX: 120, clientY: 150 });
fireEvent.pointerUp(window);
expect([dialog.style.width, dialog.style.height]).toEqual(["480px", "300px"]);
expect(dialog.style.translate).toBe("-40px 0px");
expect(onResized).toHaveBeenCalledExactlyOnceWith({ w: 480, h: 300 });
});
it("resizes from the top edge for both top popups and centered dialogs without dragging", () => {
const onResizedTop = vi.fn();
const { unmount } = render(
<Dialog
open
onClose={() => {}}
position="top"
aria-label="Top Popup"
width={400}
resizable="both"
minWidth={200}
minHeight={100}
onResized={onResizedTop}
>
<div data-dialog-drag="">header</div>
</Dialog>,
);
const topDialog = screen.getByRole("dialog");
vi.spyOn(topDialog, "getBoundingClientRect").mockReturnValue({
x: 200,
y: 120,
left: 200,
top: 120,
right: 600,
bottom: 420,
width: 400,
height: 300,
toJSON: () => ({}),
});
const topNorth = topDialog.querySelector('[data-resize="n"]') as HTMLElement;
fireEvent.pointerDown(topNorth, { button: 0, clientX: 300, clientY: 120 });
fireEvent.pointerMove(window, { buttons: 1, clientX: 350, clientY: 70 });
fireEvent.pointerUp(window);
expect([topDialog.style.width, topDialog.style.height]).toEqual(["400px", "350px"]);
expect(topDialog.style.translate).toBe("0px -50px");
expect(onResizedTop).toHaveBeenCalledExactlyOnceWith({ w: 400, h: 350 });
unmount();
const onResizedCenter = vi.fn();
render(
<Dialog
open
onClose={() => {}}
title="Centered"
width={400}
resizable="both"
minWidth={200}
minHeight={100}
onResized={onResizedCenter}
>
<div>body</div>
</Dialog>,
);
const centerDialog = screen.getByRole("dialog");
vi.spyOn(centerDialog, "getBoundingClientRect").mockReturnValue({
x: 200,
y: 150,
left: 200,
top: 150,
right: 600,
bottom: 450,
width: 400,
height: 300,
toJSON: () => ({}),
});
const centerNorth = centerDialog.querySelector('[data-resize="n"]') as HTMLElement;
fireEvent.pointerDown(centerNorth, { button: 0, clientX: 300, clientY: 150 });
fireEvent.pointerMove(window, { buttons: 1, clientX: 350, clientY: 90 });
fireEvent.pointerUp(window);
expect([centerDialog.style.width, centerDialog.style.height]).toEqual(["400px", "360px"]);
expect(centerDialog.style.translate).toBe("0px -30px");
expect(onResizedCenter).toHaveBeenCalledExactlyOnceWith({ w: 400, h: 360 });
});
it("marks data-resized when opened with initialSize", () => {
render(
<Dialog
open
onClose={() => {}}
position="top"
aria-label="Remembered"
resizable="both"
initialSize={{ w: 600, h: 400 }}
>
<div>rows</div>
</Dialog>,
);
expect(screen.getByRole("dialog")).toHaveAttribute("data-resized");
});
it("still drags a window dialog by its title bar", () => {
render(
<Dialog open onClose={() => {}} title="Usages Detected" buttons={safeDelete()} platform="other">
+129 -47
Переглянути файл
@@ -10,7 +10,7 @@ import { selectableText } from "./selectableText";
import appIcon from "../../src-tauri/icons/128x128.png";
import styles from "./Dialog.module.css";
import { isImeKey } from "@/platform/ime";
import { lockDragCursor } from "./dragCursor";
import { lockDragCursor, type DragCursor } from "./dragCursor";
import { suspendKeyboardDispatch } from "@/platform/keymap";
/**
@@ -116,9 +116,10 @@ export interface DialogProps {
footer?: ReactNode;
width?: number | string;
/**
* `both` shows a corner grip resizing the window or popup. The content lays out
* again against the new size; a numeric `width` is also the minimum width
* unless `minWidth` says otherwise.
* `both` enables resizing the window or popup from all edges and corners, with
* a visible bottom-right corner grip. The content lays out again against the
* new size; a numeric `width` is also the minimum width unless `minWidth` says
* otherwise.
*/
resizable?: "both";
minWidth?: number;
@@ -274,6 +275,23 @@ function DialogInner({
: null,
);
const fittedInitialRef = useRef(false);
useLayoutEffect(() => {
if (fittedInitialRef.current) return;
fittedInitialRef.current = true;
if (!popup || !resizable || !initialSize) return;
const el = ref.current;
if (!el) return;
const rect = el.getBoundingClientRect();
if (rect.height <= 0 || rect.bottom <= window.innerHeight - 12) return;
const minTop = Math.max(
12,
overlayTitleBar && el.parentElement ? parseFloat(getComputedStyle(el.parentElement).paddingTop) : 12,
);
const dy = Math.max(minTop - rect.top, window.innerHeight - 12 - rect.bottom);
if (dy < 0) setOffset((o) => ({ x: o.x, y: o.y + dy }));
}, [popup, resizable, initialSize, overlayTitleBar]);
useEffect(() => {
const onFocus = () => setActive(true);
const onBlur = () => setActive(false);
@@ -418,43 +436,94 @@ function DialogInner({
const hasFooter = !!(buttons?.length || footerStart || onHelp || footer);
const canResize = resizable === "both";
const resize = (e: PointerEvent<HTMLDivElement>) => {
if (e.button !== 0) return;
const el = ref.current;
if (!el) return;
e.preventDefault();
const releaseCursor = lockDragCursor("nwse-resize");
const start = { x: e.clientX, y: e.clientY };
const rect = el.getBoundingClientRect();
const minW = minWidth ?? (typeof width === "number" ? width : 320);
const chrome = el.querySelector<HTMLElement>("[data-dialog-titlebar]")?.offsetHeight ?? 0;
const minH = minHeight ?? chrome + 120;
const origin = offset;
let last: { w: number; h: number } | null = null;
const move = (ev: globalThis.PointerEvent) => {
if (!(ev.buttons & 1)) return up();
const w = Math.min(Math.max(rect.width + ev.clientX - start.x, minW), window.innerWidth - 24);
// A `top` popup grows downwards from where it sits.
const maxH = position === "top" ? window.innerHeight - rect.top - 12 : window.innerHeight - 24;
const h = Math.min(Math.max(rect.height + ev.clientY - start.y, minH), maxH);
last = { w, h };
setSize(last);
// The overlay centres the dialog (a `top` popup only horizontally): shift by half
// the growth so its top-left stays put.
setOffset({
x: origin.x + (w - rect.width) / 2,
y: position === "top" ? origin.y : origin.y + (h - rect.height) / 2,
});
const startResize =
(dxSign: -1 | 0 | 1, dySign: -1 | 0 | 1, cursor: DragCursor) => (e: PointerEvent<HTMLDivElement>) => {
if (e.button !== 0) return;
const el = ref.current;
if (!el) return;
e.preventDefault();
e.stopPropagation();
const releaseCursor = lockDragCursor(cursor);
const start = { x: e.clientX, y: e.clientY };
const rect = el.getBoundingClientRect();
const minW = minWidth ?? (typeof width === "number" ? width : 320);
const chrome = el.querySelector<HTMLElement>("[data-dialog-titlebar]")?.offsetHeight ?? 0;
const minH = minHeight ?? chrome + 120;
const minTop = Math.max(
12,
overlayTitleBar && el.parentElement ? parseFloat(getComputedStyle(el.parentElement).paddingTop) : 12,
);
const origin = offset;
let last: { w: number; h: number } | null = null;
const move = (ev: globalThis.PointerEvent) => {
if (!(ev.buttons & 1)) return up();
let w: number;
let nextX: number;
if (dxSign !== 0) {
const maxW =
rect.width > 0
? Math.max(
minW,
Math.min(window.innerWidth - 24, dxSign > 0 ? window.innerWidth - rect.left - 12 : rect.right - 12),
)
: window.innerWidth - 24;
w = Math.min(Math.max(rect.width + dxSign * (ev.clientX - start.x), minW), maxW);
nextX = origin.x + (dxSign * (w - rect.width)) / 2;
} else {
w = size?.w ?? (rect.width > 0 ? Math.max(rect.width, minW) : typeof width === "number" ? width : minW);
nextX = origin.x;
}
let h: number;
let nextY: number;
if (dySign === 1) {
const maxH =
position === "top"
? window.innerHeight - rect.top - 12
: rect.height > 0
? Math.max(minH, Math.min(window.innerHeight - 24, window.innerHeight - rect.top - 12))
: window.innerHeight - 24;
h = Math.min(Math.max(rect.height + (ev.clientY - start.y), minH), maxH);
nextY = position === "top" ? origin.y : origin.y + (h - rect.height) / 2;
} else if (dySign === -1) {
const maxH =
rect.height > 0
? Math.max(minH, Math.min(window.innerHeight - 24, rect.bottom - minTop))
: window.innerHeight - 24;
h = Math.min(Math.max(rect.height - (ev.clientY - start.y), minH), maxH);
nextY = position === "top" ? origin.y - (h - rect.height) : origin.y - (h - rect.height) / 2;
} else {
h = size?.h ?? (rect.height > 0 ? Math.max(rect.height, minH) : minH);
nextY = origin.y;
}
last = { w, h };
setSize(last);
setOffset({ x: nextX, y: nextY });
};
const up = () => {
window.removeEventListener("pointermove", move);
window.removeEventListener("pointerup", up);
releaseCursor();
if (last) onResized?.(last);
};
window.addEventListener("pointermove", move);
window.addEventListener("pointerup", up);
};
const up = () => {
window.removeEventListener("pointermove", move);
window.removeEventListener("pointerup", up);
releaseCursor();
if (last) onResized?.(last);
};
window.addEventListener("pointermove", move);
window.addEventListener("pointerup", up);
};
const resizeHandles: ReadonlyArray<{
dir: string;
className: string | undefined;
dx: -1 | 0 | 1;
dy: -1 | 0 | 1;
cursor: DragCursor;
}> = [
{ dir: "n", className: styles.resizeN, dx: 0, dy: -1, cursor: "ns-resize" },
{ dir: "s", className: styles.resizeS, dx: 0, dy: 1, cursor: "ns-resize" },
{ dir: "w", className: styles.resizeW, dx: -1, dy: 0, cursor: "ew-resize" },
{ dir: "e", className: styles.resizeE, dx: 1, dy: 0, cursor: "ew-resize" },
{ dir: "nw", className: styles.resizeNW, dx: -1, dy: -1, cursor: "nwse-resize" },
{ dir: "ne", className: styles.resizeNE, dx: 1, dy: -1, cursor: "nesw-resize" },
{ dir: "sw", className: styles.resizeSW, dx: -1, dy: 1, cursor: "nesw-resize" },
];
return createPortal(
<div
@@ -472,6 +541,7 @@ function DialogInner({
data-platform={platform}
data-alert={icon ? "" : undefined}
data-inactive={active ? undefined : ""}
data-resized={size ? "" : undefined}
className={clsx(styles.dialog, popup ? styles.popup : styles.window, className)}
onPointerDown={drag}
style={{
@@ -538,13 +608,25 @@ function DialogInner({
</div>
)}
{canResize && (
<div
className={styles.resizeGrip}
role="separator"
aria-orientation="vertical"
aria-label={tx("Resize")}
onPointerDown={resize}
/>
<>
{resizeHandles.map((h) => (
<div
key={h.dir}
aria-hidden="true"
data-resize={h.dir}
className={clsx(styles.resizeEdge, h.className)}
onPointerDown={startResize(h.dx, h.dy, h.cursor)}
/>
))}
<div
className={styles.resizeGrip}
data-resize="se"
role="separator"
aria-orientation="vertical"
aria-label={tx("Resize")}
onPointerDown={startResize(1, 1, "nwse-resize")}
/>
</>
)}
</div>
</div>,
+8 -1
Переглянути файл
@@ -1,4 +1,11 @@
export type DragCursor = "move" | "col-resize" | "row-resize" | "ew-resize" | "ns-resize" | "nwse-resize";
export type DragCursor =
| "move"
| "col-resize"
| "row-resize"
| "ew-resize"
| "ns-resize"
| "nwse-resize"
| "nesw-resize";
const active = new Set<() => void>();
let listening = false;