diff --git a/e2e/editor.spec.ts b/e2e/editor.spec.ts index 1eb7ad204..6a920e902 100644 --- a/e2e/editor.spec.ts +++ b/e2e/editor.spec.ts @@ -232,6 +232,48 @@ test("⌘R replaces every match in the file", async ({ workbench: page }) => { await expect(editor.locator(".cm-line", { hasText: "OrderDto" })).toHaveCount(2); }); +test("the inline find and replace controls stay inside a narrow editor pane", async ({ workbench: page }) => { + await page.setViewportSize({ width: 1120, height: 760 }); + const editor = await openFromTree(page, "build.gradle.kts"); + await editor.locator(".cm-content").click(); + await page.keyboard.press("Meta+r"); + const bar = page.getByRole("search", { name: "Replace in file" }); + const find = bar.getByRole("textbox", { name: "Find" }); + const replace = bar.getByRole("textbox", { name: "Replace" }); + const next = bar.getByRole("button", { name: /Next Occurrence/ }); + await find.fill("OrderDto"); + await find.press("Tab"); + await expect(replace).toBeFocused(); + await replace.fill("OrderView"); + const navigationIsBelowFind = async () => { + const [input, button] = await Promise.all([find.boundingBox(), next.boundingBox()]); + return !!input && !!button && button.y >= input.y + input.height; + }; + const controlsFit = () => + bar.evaluate((panel) => { + const bounds = panel.getBoundingClientRect(); + return [...panel.querySelectorAll("button, textarea")].every((element) => { + const control = element.getBoundingClientRect(); + return control.width > 0 && control.left >= bounds.left && control.right <= bounds.right; + }); + }); + await expect.poll(navigationIsBelowFind).toBe(false); + + await page.setViewportSize({ width: 590, height: 760 }); + await expect.poll(controlsFit).toBe(true); + await expect.poll(navigationIsBelowFind).toBe(true); + await page.setViewportSize({ width: 495, height: 760 }); + await expect.poll(controlsFit).toBe(true); + await expect(find).toHaveValue("OrderDto"); + await expect(replace).toHaveValue("OrderView"); + await next.click(); + await expect(bar.getByText(/^[12]\/2$/)).toBeVisible(); + await bar.getByRole("button", { name: "Replace All" }).click(); + await expect(editor.locator(".cm-line", { hasText: "OrderView" })).toHaveCount(2); + await bar.getByRole("button", { name: "Close", exact: true }).click(); + await expect(bar).toBeHidden(); +}); + test("Markdown preview highlights ⌘F matches, selected words and scales diagrams with font zoom", async ({ workbench: page, }) => { diff --git a/src/editor/core/view/EditorArea.module.css b/src/editor/core/view/EditorArea.module.css index e491b6ae3..c813c5257 100644 --- a/src/editor/core/view/EditorArea.module.css +++ b/src/editor/core/view/EditorArea.module.css @@ -151,52 +151,126 @@ } /* Find / replace bar */ -.find { +.findContainer { flex: none; - display: grid; - grid-template-columns: minmax(220px, 420px) auto 1fr; - align-items: center; - column-gap: var(--space-1-5); - row-gap: var(--space-1-5); - padding: 6px 8px 6px 10px; + min-width: 0; + container: editor-find / inline-size; background: var(--bg-editor-inline, var(--bg-elev)); border-bottom: 1px solid var(--border-editor-tabs, var(--border)); } -.findExpandable { - grid-template-columns: auto minmax(220px, 420px) auto 1fr; +.find { + display: grid; + grid-template-columns: [mode] auto [field] minmax(0, 420px) [actions] fit-content(50%) [close] minmax( + min-content, + 1fr + ); + align-items: start; + row-gap: var(--space-1); + padding: var(--space-1-5) var(--space-2); } .findExpand { - grid-column: 1; - grid-row: 1; -} -.findExpandable .findField { - grid-column: 2; + grid-area: 1 / mode; + margin-inline-end: var(--space-1); } .findField { + grid-area: 1 / field; +} +.replaceField { + grid-area: 2 / field; +} +.findField, +.replaceField { min-width: 0; } -.findButtons { +.findClose { + grid-area: 1 / close; + justify-self: end; + margin-inline-start: var(--space-1); +} +.findExpand, +.findClose { + margin-block-start: var(--space-1); +} +.findButtons, +.replaceButtons { display: flex; + flex-wrap: wrap; align-items: center; + min-width: 0; + min-height: var(--h-field); + margin-inline-start: var(--space-1-5); +} +.findButtons { + grid-area: 1 / actions; gap: var(--space-0-5); } +.replaceButtons { + grid-area: 2 / actions; + gap: var(--space-1); +} .findCount { - font-size: var(--fs-ui); + min-inline-size: 5ch; + padding-inline: var(--space-1); + font-size: var(--fs-small); + font-variant-numeric: tabular-nums; color: var(--fg-subtle); - padding: 0 8px 0 4px; - min-width: 56px; white-space: nowrap; } .findCountNone { color: var(--danger); } -.findClose { - justify-self: end; + +@container editor-find (width < 500px) { + .find { + grid-template-columns: [mode] auto [field] minmax(0, 1fr) [close] auto; + } + .findButtons, + .replaceButtons { + grid-column: field / -1; + min-height: 0; + margin-inline-start: 0; + } + .findButtons { + grid-row: 2; + } + .replaceField { + grid-row: 3; + } + .replaceButtons { + grid-row: 4; + } + .replaceButtons > button { + max-width: 100%; + height: auto; + min-height: var(--h-control); + white-space: normal; + overflow-wrap: anywhere; + } } -.replaceButtons { - display: flex; - align-items: center; - gap: var(--space-1-5); + +@container editor-find (width < 224px) { + .findField, + .replaceField, + .replaceButtons { + grid-column: mode / -1; + } + .findExpand, + .findClose { + grid-row: 2; + margin-block-start: 0; + } + .findButtons { + grid-column: field; + } + .findInput { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(20px, 1fr)); + height: auto; + padding-block: var(--space-1); + } + .findInput textarea { + grid-column: 2 / -1; + } } /* Go to line */ diff --git a/src/editor/core/view/FindBar.tsx b/src/editor/core/view/FindBar.tsx index f419e138d..1b4a89b6b 100644 --- a/src/editor/core/view/FindBar.tsx +++ b/src/editor/core/view/FindBar.tsx @@ -608,182 +608,185 @@ export function FindPanel({ target, version, replace, seq, onReplaceShown, onClo const canReplace = !!opts.search && !invalid; return ( -
{ - focusedTarget = target; - setContext("findBarFocus", true); - setContext( - "findBarHasResults", - !!target.results && !!opts.search && (!opts.regexp || regexValid(opts.search)) && !!count?.total, - ); - }} - onBlurCapture={(e) => { - if (!panelRef.current?.contains(e.relatedTarget as Node | null)) setContext("findBarFocus", false); - }} - className={clsx(styles.find, onReplaceShown && styles.findExpandable)} - role="search" - aria-label={replace ? "Replace in file" : "Find in file"} - > - {onReplaceShown && ( - e.preventDefault()} - onClick={() => { - if (replaceBoxRef.current?.contains(document.activeElement)) inputRef.current?.focus(); - onReplaceShown(!replace); - }} +
+
{ + focusedTarget = target; + setContext("findBarFocus", true); + setContext( + "findBarHasResults", + !!target.results && !!opts.search && (!opts.regexp || regexValid(opts.search)) && !!count?.total, + ); + }} + onBlurCapture={(e) => { + if (!panelRef.current?.contains(e.relatedTarget as Node | null)) setContext("findBarFocus", false); + }} + className={styles.find} + role="search" + aria-label={replace ? "Replace in file" : "Find in file"} + > + {onReplaceShown && ( + e.preventDefault()} + onClick={() => { + if (replaceBoxRef.current?.contains(document.activeElement)) inputRef.current?.focus(); + onReplaceShown(!replace); + }} + /> + )} +
+ setOpts({ search })} + placeholder="Find" + aria-label="Find" + invalid={invalid || none} + multiline + onHistory={() => setHistoryMenu("find")} + onKeyDown={(e) => onKeyDown(e, "find")} + className={styles.findInput} + toggles={[ + { + id: "case", + icon: "case", + title: "Match Case", + shortcut: formatBinding("Alt+C"), + pressed: opts.caseSensitive, + onToggle: () => toggle("caseSensitive"), + }, + { + id: "word", + icon: "word", + title: "Words", + shortcut: formatBinding("Alt+W"), + pressed: opts.wholeWord, + onToggle: () => toggle("wholeWord"), + }, + { + id: "regex", + icon: "regex", + title: "Regex", + shortcut: formatBinding("Alt+X"), + pressed: opts.regexp, + onToggle: () => toggle("regexp"), + }, + ]} + /> +
+
+ + {counter} + + run(findPrevious)} + /> + run(findNext)} + /> + setFilterMenu(true)} + /> + setMoreMenu(true)} /> +
+ + {replace && ( + <> +
+ setOpts({ replace: value })} + placeholder="Replace" + aria-label="Replace" + multiline + onHistory={() => setHistoryMenu("replace")} + onKeyDown={(e) => onKeyDown(e, "replace")} + toggles={[ + { + id: "preserveCase", + icon: "preserve-case", + title: "Preserve Case", + pressed: opts.preserveCase, + onToggle: () => toggle("preserveCase"), + }, + ]} + /> +
+
+ + + +
+ + )} + setHistoryMenu(null)} /> - )} -
- setOpts({ search })} - placeholder="Find" - aria-label="Find" - invalid={invalid || none} - multiline - onHistory={() => setHistoryMenu("find")} - onKeyDown={(e) => onKeyDown(e, "find")} - toggles={[ - { - id: "case", - icon: "case", - title: "Match Case", - shortcut: formatBinding("Alt+C"), - pressed: opts.caseSensitive, - onToggle: () => toggle("caseSensitive"), - }, - { - id: "word", - icon: "word", - title: "Words", - shortcut: formatBinding("Alt+W"), - pressed: opts.wholeWord, - onToggle: () => toggle("wholeWord"), - }, - { - id: "regex", - icon: "regex", - title: "Regex", - shortcut: formatBinding("Alt+X"), - pressed: opts.regexp, - onToggle: () => toggle("regexp"), - }, - ]} + setMoreMenu(false)} + /> + setFilterMenu(false)} />
-
- - {counter} - - run(findPrevious)} - /> - run(findNext)} - /> - setFilterMenu(true)} - /> - setMoreMenu(true)} /> -
- - {replace && ( - <> -
- setOpts({ replace: value })} - placeholder="Replace" - aria-label="Replace" - multiline - onHistory={() => setHistoryMenu("replace")} - onKeyDown={(e) => onKeyDown(e, "replace")} - toggles={[ - { - id: "preserveCase", - icon: "preserve-case", - title: "Preserve Case", - pressed: opts.preserveCase, - onToggle: () => toggle("preserveCase"), - }, - ]} - /> -
-
- - - -
- - )} - setHistoryMenu(null)} - /> - setMoreMenu(false)} - /> - setFilterMenu(false)} - />
); }