Compare commits

...
Author SHA1 Message Date
l0ng-ai 6080e1f3a2 fix(editor): keep multiline find and replace compact 2026-11-23 12:56:06 +08:00
3 changed files with 50 additions and 1 deletions

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
import { expect, openFromTree, test } from "./fixtures";
test("multiline editor search keeps three visible lines and replaces with the full text", async ({
workbench: page,
}) => {
const editor = await openFromTree(page, "build.gradle.kts");
await page.setViewportSize({ width: 540, height: 500 });
const content = editor.locator(".cm-content");
const query = "currency=EUR\nregion=eu-west\npipeline=clearing\nmode=batch\ntimeout=30\nretries=2";
const replacement = query.replace("clearing", "settlement").replace("timeout=30", "timeout=45");
await content.press("Meta+a");
await page.keyboard.insertText(`[ledger]\n${query}\n\n[reporting]\n${query}\n`);
await content.press("Escape");
await content.press("Meta+r");
const bar = page.getByRole("search", { name: "Replace in file" });
const find = bar.getByRole("textbox", { name: "Find", exact: true });
const replace = bar.getByRole("textbox", { name: "Replace", exact: true });
await find.fill(query);
await replace.fill(replacement);
for (const field of [find, replace]) {
const visibleLines = await field.evaluate((el) => el.clientHeight / parseFloat(getComputedStyle(el).lineHeight));
expect(visibleLines).toBeCloseTo(3);
await field.press("Control+End");
await expect.poll(() => field.evaluate((el) => el.scrollTop)).toBeGreaterThan(0);
}
await expect(find).toHaveValue(query);
await expect(replace).toHaveValue(replacement);
const count = bar.locator("[aria-live]");
await expect(count).toHaveText(/\/2$/);
const selected = await count.innerText();
const next = bar.getByRole("button", { name: /Next Occurrence/ });
await next.click();
await expect(count).toHaveText(/^[12]\/2$/);
await expect(count).not.toHaveText(selected);
await bar.getByRole("button", { name: "Replace All", exact: true }).click();
await expect(editor.locator(".cm-line", { hasText: "timeout=45" })).toHaveCount(2);
await expect(editor.locator(".cm-line", { hasText: "pipeline=clearing" })).toHaveCount(0);
await bar.getByRole("button", { name: "Close", exact: true }).click();
await expect(content).toBeFocused();
await content.press("Meta+z");
await expect(editor.locator(".cm-line", { hasText: "pipeline=clearing" })).toHaveCount(2);
});
+2
View File
@@ -640,6 +640,7 @@ export function FindPanel({ target, version, replace, seq, onReplaceShown, onClo
aria-label="Find"
invalid={invalid || none}
multiline
maxRows={3}
onHistory={() => setHistoryMenu("find")}
onKeyDown={(e) => onKeyDown(e, "find")}
className={styles.findInput}
@@ -710,6 +711,7 @@ export function FindPanel({ target, version, replace, seq, onReplaceShown, onClo
placeholder="Replace"
aria-label="Replace"
multiline
maxRows={3}
onHistory={() => setHistoryMenu("replace")}
onKeyDown={(e) => onKeyDown(e, "replace")}
toggles={[
+4 -1
View File
@@ -95,6 +95,8 @@ export interface SearchFieldProps extends Omit<InputHTMLAttributes<HTMLInputElem
* text, plus a New Line button (⇧⌘↵ / ⇧Ctrl↵ inserts one too).
*/
multiline?: boolean;
/** How many lines of a search query stay visible before the field scrolls. */
maxRows?: number;
/** Turns the leading magnifier into IDEA's search-history button (magnifier ▾). */
onHistory?: () => void;
}
@@ -132,6 +134,7 @@ export const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(functi
className,
placeholder,
multiline,
maxRows = 5,
onHistory,
"aria-label": ariaLabel,
...rest
@@ -227,7 +230,7 @@ export const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(functi
<textarea
ref={setRef as Ref<HTMLTextAreaElement>}
className={clsx(styles.searchInput, styles.searchArea, lines === 1 && styles.searchAreaSingle)}
rows={Math.min(lines, 5)}
rows={Math.min(lines, maxRows)}
wrap="off"
value={value}
spellCheck={false}