Phase 4c. The Markdown, code, Read, and image menus open through showActionMenu. It closes a menu on an outside press, an outside scroll, a resize, and window blur. A host surface now gives its own focus return, so four copies of the listener code are gone. - menuItems.ts builds Undo, Redo, the clipboard rows, and the search row. The Markdown, code, Read, table cell, and table range menus use it. The Markdown and table menus now show the shortcuts for Cut, Copy, Paste, and Select all, as the other menus did. - writerSearch.ts is now editorSearch.ts, because it serves Write and Source. - Plugins still get only close() from api.ui.showActionMenu. The SDK menu types do not change. - The table range menu and the native spelling menu keep their own lifecycle, because their open state drives table editing and the native spelling protocol. - docs/ui-design.md names the shared rows and the search modules. The menu inventory has the new count for markdownMenu.ts. pnpm check, pnpm test (341 of 341), and the full smoke suite pass, except tables/formulas, which failed one time under load and passed on retry.
118 lines
6.5 KiB
JavaScript
118 lines
6.5 KiB
JavaScript
// Writer find bar in the top editor panel: shortcuts, replacement, query sync, invalid regex, tooltip, outline filtering, focus return, and narrow layout.
|
|
import assert from "node:assert/strict";
|
|
import path from "node:path";
|
|
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("find/searchPanel", async ({ page }) => {
|
|
const output = await outputDir("find/searchPanel");
|
|
await mockTauri(page, {
|
|
commands: test => {
|
|
const workspace = test.workspace({
|
|
root: "C:\\smoke-workspace",
|
|
writeEvents: true,
|
|
files: {
|
|
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
|
|
"notes/second.md": "# Second note\n",
|
|
"src/hello.py": "print('hello')\n",
|
|
},
|
|
});
|
|
return {
|
|
...workspace,
|
|
workspace_write: args => {
|
|
if (args.expected !== undefined && workspace.files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
|
return workspace.workspace_write(args);
|
|
},
|
|
workspace_search: () => [],
|
|
"plugin:dialog|message": () => "Cancel",
|
|
};
|
|
},
|
|
});
|
|
await page.goto(smokeUrl);
|
|
await page.getByText("smoke-workspace", { exact: true }).waitFor();
|
|
await page.keyboard.press("Control+p");
|
|
await page.getByRole("textbox", { name: "Find a file" }).fill("welcome.md");
|
|
await page.getByRole("dialog").getByRole("button").filter({ hasText: "welcome.md" }).first().click();
|
|
const editor = page.getByRole("textbox", { name: "Writing editor", exact: true });
|
|
await editor.waitFor();
|
|
await page.evaluate(async () => {
|
|
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
|
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
|
window.__CM__.dispatch({ changes: { from: 0, to: window.__CM__.state.doc.length, insert: "# Alpha\n\nalpha Alpha alphabet\n\n## Beta\n\nBeta text\n" }, selection: { anchor: 0 } });
|
|
window.__CM__.focus();
|
|
});
|
|
await page.keyboard.press("Control+f");
|
|
const find = page.getByRole("textbox", { name: "Find in document", exact: true });
|
|
await find.waitFor();
|
|
assert.equal(await find.evaluate(el => document.activeElement === el), true);
|
|
assert.equal(await page.locator(".cm-panels-top .rs-editor-search").count(), 1);
|
|
const panelBounds = await page.locator(".rs-editor-search").boundingBox();
|
|
const scrollBounds = await page.locator(".cm-scroller").boundingBox();
|
|
assert.ok(panelBounds.y + panelBounds.height <= scrollBounds.y + 1);
|
|
await find.fill("Alpha");
|
|
await page.keyboard.press("Enter");
|
|
const first = await page.evaluate(() => window.__CM__.state.selection.main.from);
|
|
await page.keyboard.press("Enter");
|
|
const second = await page.evaluate(() => window.__CM__.state.selection.main.from);
|
|
assert.notEqual(first, second);
|
|
await page.keyboard.press("Shift+Enter");
|
|
assert.equal(await page.evaluate(() => window.__CM__.state.selection.main.from), first);
|
|
await page.getByRole("checkbox", { name: "Match case" }).check();
|
|
await page.getByRole("checkbox", { name: "Whole word" }).check();
|
|
await page.getByRole("textbox", { name: "Replace with" }).fill("Gamma");
|
|
await page.getByRole("button", { name: "Replace all", exact: true }).click();
|
|
assert.match(await page.evaluate(() => window.__CM__.state.sliceDoc()), /# Gamma\n\nalpha Gamma alphabet/);
|
|
await page.getByRole("checkbox", { name: "Regex" }).check();
|
|
await find.fill("[");
|
|
assert.equal(await find.getAttribute("aria-invalid"), "true");
|
|
assert.equal(await page.getByRole("button", { name: "Replace all", exact: true }).isDisabled(), true);
|
|
await page.getByText("Invalid expression", { exact: true }).waitFor();
|
|
await find.fill("Gamma");
|
|
await page.getByRole("checkbox", { name: "Regex" }).uncheck();
|
|
await page.evaluate(async () => {
|
|
const moduleUrl = performance.getEntriesByType("resource").find(entry => entry.name.includes("/@codemirror_search.js"))?.name;
|
|
if (!moduleUrl) throw new Error("Search module was not loaded");
|
|
const { SearchQuery, setSearchQuery } = await import(moduleUrl);
|
|
window.__CM__.dispatch({ effects: setSearchQuery.of(new SearchQuery({ search: "Beta" })) });
|
|
});
|
|
await page.waitForFunction(() => document.querySelector('input[name="search"]').value === "Beta");
|
|
await find.focus();
|
|
await page.keyboard.press("Escape");
|
|
assert.equal(await find.count(), 0);
|
|
assert.equal(await editor.evaluate(el => document.activeElement === el), true);
|
|
await page.keyboard.press("Control+f");
|
|
await find.waitFor();
|
|
await page.getByRole("button", { name: "Next match (Enter)" }).focus();
|
|
await page.getByRole("tooltip", { name: "Next match (Enter)" }).waitFor({ state: "visible" });
|
|
await find.focus();
|
|
|
|
const outline = page.getByRole("region", { name: "Outline", exact: true });
|
|
if (!await outline.count()) await page.getByRole("button", { name: "Outline", exact: true }).click();
|
|
await outline.focus();
|
|
await page.keyboard.press("Control+f");
|
|
const outlineFind = page.getByRole("textbox", { name: "Find in outline", exact: true });
|
|
await outlineFind.fill("beta");
|
|
assert.equal(await outline.locator("li").count(), 1);
|
|
assert.equal(await outline.locator("li button").textContent(), "Beta");
|
|
await outlineFind.fill("missing");
|
|
await outline.getByText("No matching headings or symbols.").waitFor();
|
|
await outlineFind.fill("Gamma");
|
|
await page.screenshot({ path: path.join(output, "find-bars.png") });
|
|
await page.keyboard.press("Escape");
|
|
assert.equal(await outlineFind.count(), 0);
|
|
assert.equal(await outline.locator("li").count(), 2);
|
|
assert.equal(await outline.evaluate(el => document.activeElement === el), true);
|
|
await page.keyboard.press("Control+f");
|
|
await outlineFind.fill("Beta");
|
|
await page.keyboard.press("Enter");
|
|
await page.waitForFunction(() => window.__CM__.state.doc.lineAt(window.__CM__.state.selection.main.head).text === "## Beta");
|
|
assert.equal(await editor.evaluate(el => document.activeElement === el), true);
|
|
|
|
await page.setViewportSize({ width: 880, height: 760 });
|
|
await find.focus();
|
|
await page.screenshot({ path: path.join(output, "find-bars-narrow.png") });
|
|
for (const selector of [".rs-editor-search", ".outline-search"]) {
|
|
assert.equal(await page.locator(selector).evaluate(el => el.scrollWidth <= el.clientWidth), true, selector);
|
|
}
|
|
console.log("PASS: Top search panel, shortcuts, replacement, query sync, invalid regex, focus tooltip, outline filtering, focus return and narrow layout.");
|
|
});
|