diff --git a/e2e/searchScopesDialogLayout.spec.ts b/e2e/searchScopesDialogLayout.spec.ts new file mode 100644 index 0000000000..9c93ad66c1 --- /dev/null +++ b/e2e/searchScopesDialogLayout.spec.ts @@ -0,0 +1,59 @@ +import { expect, test } from "./fixtures"; + +test("Find in Files keeps the scope list and pattern editor usable in a narrow window", async ({ workbench: page }) => { + await page.setViewportSize({ width: 1040, height: 700 }); + const longName = "Regional settlement reconciliation sources for month-end audit and publication"; + await page.evaluate(async (longName) => { + const search = "/src/platform/search.ts"; + const { saveCustomScopes } = await import(/* @vite-ignore */ search); + saveCustomScopes( + Array.from({ length: 26 }, (_, i) => ({ + name: i ? `Reconciliation scope ${i + 1}` : longName, + pattern: i ? `file:src/scope-${i + 1}//*` : "file:src/reconciliation//*", + })), + ); + }, longName); + await page.keyboard.press("Meta+Shift+F"); + const find = page.getByRole("dialog", { name: "Find in Files", exact: true }); + await find.getByRole("tab", { name: "Scope", exact: true }).click(); + const openScopes = find.getByRole("button", { name: "Edit Scopes…", exact: true }); + await openScopes.click(); + + const dialog = page.getByRole("dialog", { name: "Scopes", exact: true }); + const list = dialog.getByRole("list", { name: "Scopes", exact: true }); + const name = dialog.getByRole("textbox", { name: "Name:", exact: true }); + const pattern = dialog.getByRole("textbox", { name: "Pattern:", exact: true }); + await expect(pattern).toHaveValue("file:src/reconciliation//*"); + expect(await list.evaluate((el) => el.scrollHeight - el.clientHeight)).toBeGreaterThan(100); + await expect(list.getByRole("button", { name: longName })).toHaveAttribute("title", longName); + expect((await list.boundingBox())!.x).toBeLessThan((await name.boundingBox())!.x); + + await page.setViewportSize({ width: 460, height: 530 }); + const fields = (await pattern.boundingBox())!; + expect(fields.y).toBeGreaterThanOrEqual((await list.boundingBox())!.y + (await list.boundingBox())!.height); + expect(fields.width).toBeGreaterThan(250); + await list.evaluate((el) => (el.scrollTop = el.scrollHeight)); + expect((await pattern.boundingBox())!.y).toBeCloseTo(fields.y, 0); + const toolbar = dialog.getByRole("toolbar", { name: "Scopes actions" }); + const add = toolbar.getByRole("button", { name: "Add Scope", exact: true }); + const ok = dialog.getByRole("button", { name: "OK", exact: true }); + await expect(add).toBeInViewport({ ratio: 1 }); + await expect(ok).toBeInViewport({ ratio: 1 }); + + await name.fill("Unsaved selection"); + await dialog.getByRole("button", { name: "Cancel", exact: true }).click(); + await openScopes.click(); + await expect(name).toHaveValue(longName); + await add.click(); + const draft = list.getByRole("button", { name: "Unnamed", exact: true }); + await expect(draft).toHaveAttribute("aria-current", "true"); + await expect(draft).toBeInViewport({ ratio: 1 }); + await expect(ok).toBeDisabled(); + await name.fill("Release inputs"); + await pattern.fill("file:src/release//*"); + await ok.click(); + await expect(dialog).toBeHidden(); + await openScopes.click(); + await list.getByRole("button", { name: "Release inputs", exact: true }).click(); + await expect(pattern).toHaveValue("file:src/release//*"); +}); diff --git a/src/features/search/find/ScopesDialog.module.css b/src/features/search/find/ScopesDialog.module.css index c52c4d1bb4..8dad19edb4 100644 --- a/src/features/search/find/ScopesDialog.module.css +++ b/src/features/search/find/ScopesDialog.module.css @@ -1,26 +1,32 @@ .body { display: grid; - grid-template-columns: 200px 1fr; - min-height: 300px; + grid-template-columns: 200px minmax(0, 1fr); + grid-template-rows: minmax(0, 1fr); + height: clamp(240px, 55vh, 360px); border: 1px solid var(--border); border-radius: var(--radius-small); + overflow: hidden; } .side { display: flex; flex-direction: column; min-width: 0; - border-right: 1px solid var(--border); + min-height: 0; + border-inline-end: 1px solid var(--border); } .toolbar { display: flex; + flex: none; gap: var(--space-0-5); - padding: 4px; + padding: var(--space-1); border-bottom: 1px solid var(--border); } .list { flex: 1; + min-height: 0; margin: 0; - padding: 4px; + padding: var(--space-1); + scroll-padding-block: var(--space-1); list-style: none; overflow: auto; } @@ -29,13 +35,16 @@ align-items: center; width: 100%; height: var(--h-list-row); - padding: 0 8px; + padding: 0 var(--space-2); border: 0; border-radius: var(--radius-row); background: none; color: var(--fg); font-size: var(--fs-ui); - text-align: left; + text-align: start; +} +.item > span { + min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; @@ -47,16 +56,25 @@ background: var(--bg-list-selected); } .empty { - padding: 8px; + padding: var(--space-2); color: var(--fg-muted); font-size: var(--fs-ui); } .form { - display: flex; - flex-direction: column; - gap: var(--space-1-5); - padding: 10px 14px; + display: grid; + grid-template-columns: max-content minmax(0, 1fr); + align-items: center; + align-content: start; + gap: var(--space-2) var(--space-3); + padding: var(--space-3); min-width: 0; + min-height: 0; + overflow: auto; +} +.form > .error, +.form > .empty, +.help { + grid-column: 1 / -1; } .label { color: var(--fg-muted); @@ -65,10 +83,11 @@ .error { color: var(--danger); font-size: var(--fs-small); + overflow-wrap: anywhere; } .help { - margin: 6px 0 0; - padding-left: 16px; + margin: 0; + padding-inline-start: var(--space-4); color: var(--fg-muted); font-size: var(--fs-small); line-height: 1.6; @@ -77,3 +96,15 @@ font-family: var(--font-mono); color: var(--fg); } + +@media (max-width: 540px) { + .body { + grid-template-columns: minmax(0, 1fr); + grid-template-rows: minmax(84px, 1fr) minmax(0, auto); + height: clamp(240px, 65vh, 360px); + } + .side { + border-inline-end: 0; + border-bottom: 1px solid var(--border); + } +} diff --git a/src/features/search/find/ScopesDialog.tsx b/src/features/search/find/ScopesDialog.tsx index 4733a3f82f..e3f2d68912 100644 --- a/src/features/search/find/ScopesDialog.tsx +++ b/src/features/search/find/ScopesDialog.tsx @@ -3,7 +3,7 @@ * file pattern, saved per project (`@/platform/search`) and offered wherever * named scopes are (Find in Files, the analyses' Specify Scope). */ -import { useEffect, useId, useState } from "react"; +import { useEffect, useId, useLayoutEffect, useRef, useState } from "react"; import clsx from "clsx"; import { create } from "zustand"; import { tx, txTemplate, useTx, useTxTemplate } from "@/platform/i18n"; @@ -88,6 +88,10 @@ function ScopesDialog() { const select = useScopesDialog.getState().select; return Math.max(0, select ? scopes.findIndex((s) => s.name === select) : 0); }); + const selectedRow = useRef(null); + useLayoutEffect(() => { + selectedRow.current?.scrollIntoView({ block: "nearest" }); + }, [index, scopes.length]); const current = scopes[index] ?? null; const patternError = usePatternError(current?.pattern ?? ""); const problem = scopesProblem(scopes); @@ -124,7 +128,7 @@ function ScopesDialog() { >
-
+
@@ -134,11 +138,13 @@ function ScopesDialog() {
  • ))}