Improve workspace navigation, search, and tab actions

This commit is contained in:
Knotty Wyvern
2026-09-29 07:48:24 -07:00
parent bdc15e952d
commit 43106ed9c7
34 changed files with 1798 additions and 100 deletions
+167
View File
@@ -0,0 +1,167 @@
// Run against `pnpm dev`. PLAYWRIGHT_MODULE may point to a shared installation.
import { createRequire } from "node:module";
import assert from "node:assert/strict";
import { mkdir } from "node:fs/promises";
const require = createRequire(import.meta.url);
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
page.setDefaultTimeout(10000);
const errors = [];
await mkdir(".audit", { recursive: true });
page.on("console", message => { if (message.type() === "error" || message.type() === "warning") console.log(message.type(), message.text()); });
page.on("pageerror", error => errors.push(error.message));
await page.addInitScript(() => {
window.isTauri = true;
const root = "C:\\smoke-workspace";
const files = new Map([
["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"],
]);
const callbacks = new Map();
const listeners = new Map();
let sequence = 0;
const calls = [];
const emit = (event, payload) => {
for (const id of listeners.get(event) || []) callbacks.get(id)?.({ event, id, payload });
};
window.__TAURI_INTERNALS__ = {
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
transformCallback: callback => { const id = ++sequence; callbacks.set(id, callback); return id; },
unregisterCallback: id => callbacks.delete(id),
invoke: async (command, args = {}) => {
calls.push({ command, args });
if (command === "plugin:event|listen") {
const list = listeners.get(args.event) || []; list.push(args.handler); listeners.set(args.event, list); return args.handler;
}
if (command === "plugin:event|unlisten") { callbacks.delete(args.eventId); return; }
if (command === "workspace_last_path") return root;
if (command === "workspace_open") return { root, name: "smoke-workspace", watch_mode: "native" };
if (command === "workspace_read") { if (!files.has(args.rel)) throw new Error("missing"); return files.get(args.rel); }
if (command === "workspace_write") {
if (args.expected !== undefined && files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
files.set(args.rel, args.contents); emit("workspace-event", { root, kind: "modify", paths: [args.rel] }); return;
}
if (command === "workspace_list") {
const prefix = args.rel ? args.rel + "/" : "";
const entries = new Map();
for (const path of files.keys()) {
if (!path.startsWith(prefix) || path.startsWith(".runestone/")) continue;
const tail = path.slice(prefix.length); const name = tail.split("/")[0];
entries.set(name, { name, rel_path: prefix + name, kind: tail.includes("/") ? "folder" : "file" });
}
return [...entries.values()];
}
if (command === "workspace_create") { if (files.has(args.rel)) throw new Error("exists"); files.set(args.rel, ""); return; }
if (command === "workspace_search") return [];
if (command === "pty_open") {
const data = [...new TextEncoder().encode("READY 🪨\r\n\x1b[6n")];
emit("pty-data", { id: args.id, data: data.slice(0, 8) });
emit("pty-data", { id: args.id, data: data.slice(8) });
await new Promise(resolve => setTimeout(resolve, 50));
return;
}
if (command.startsWith("pty_")) return;
if (command === "plugin:dialog|message") return "Cancel";
throw new Error(`Unhandled IPC: ${command}`);
},
};
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: (_event, id) => callbacks.delete(id) };
window.__TEST__ = { files, calls, emit, root };
});
try {
await page.goto(process.env.SMOKE_URL || "http://127.0.0.1:1420");
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-writer-search").count(), 1);
const panelBounds = await page.locator(".rs-writer-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: ".audit/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: ".audit/find-bars-narrow.png" });
for (const selector of [".rs-writer-search", ".outline-search"]) {
assert.equal(await page.locator(selector).evaluate(el => el.scrollWidth <= el.clientWidth), true, selector);
}
assert.deepEqual(errors, []);
console.log("PASS: Top search panel, shortcuts, replacement, query sync, invalid regex, focus tooltip, outline filtering, focus return and narrow layout.");
} catch (error) {
console.error("Browser errors:", errors);
await page.screenshot({ path: ".audit/find-failure.png" });
throw error;
} finally { await browser.close(); }