Phase 4b. DocumentEditor.svelte replaces LiveWriter.svelte and the Monaco EditorHost.svelte. Each open document has one CodeMirror state. Write and Source are two compartment configurations of it, so they share the undo history. editorStates.ts keeps the state while the tab stays open. The Monaco model, the diff bridge, its timers, and sessions.ts are gone. - Source: syntax colors from the theme tokens, lazy language packages, line numbers, folding, and the current line in IDE, wrapped lines in Writing, several carets, and bracket matching and closing. - Lists (card 088e778b): Tab nests a list item and Shift+Tab moves it up, in Write and Source. Both renumber the list. The source keeps "1.". Write and Read show numbers, letters, then Roman numerals. - Indent (card 696c30ce): a fixed 4 spaces in Write and Source. - The code menu uses CodeMirror commands. The command palette item and the Monaco styles, search, theme, and workers are removed. - @codemirror/legacy-modes is pinned to 6.5.4. Version 6.5.5 uses parser types that do not match @codemirror/language 6.12. - 26 smoke tests use CodeMirror instead of Monaco. New tests: editor/listNesting and the markdownLists unit tests. - Docs: development, UI design, plugin host, user guide, and UI-040. pnpm check, pnpm test (341 of 341), and pnpm build pass. The full smoke suite passes, except one template test that passed on retry.
135 lines
8.6 KiB
JavaScript
135 lines
8.6 KiB
JavaScript
// Workspace menu: recent history, opening and creating workspaces in new windows, cancellation, errors, keyboard use, removal, and the empty state.
|
|
import assert from "node:assert/strict";
|
|
import path from "node:path";
|
|
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("workspace/openAndCreate", async ({ page }) => {
|
|
const output = await outputDir("workspace/openAndCreate");
|
|
// Unknown commands return null, as the original mock did.
|
|
await mockTauri(page, {
|
|
strict: false,
|
|
commands: test => {
|
|
let current = "D:\\Notes";
|
|
let recent = ["D:\\Writing\\Notes", current, "D:\\Missing"];
|
|
let picked = null;
|
|
let contents = "Original note";
|
|
const windows = [];
|
|
Object.assign(test, { windows, pick: path => picked = path, clear: () => recent = [], reorder: () => recent = ["D:\\Writing\\Notes", current, "D:\\Missing"] });
|
|
return {
|
|
workspace_last_path: () => current,
|
|
workspace_recent: () => recent,
|
|
workspace_forget: args => { recent = recent.filter(path => path !== args.path); return recent; },
|
|
workspace_list: args => args.rel ? [] : [{ name: "note.txt", rel_path: "note.txt", kind: "file" }],
|
|
workspace_read: args => { if (args.rel === "note.txt") return contents; throw "File not found"; },
|
|
workspace_write: args => { contents = args.contents; },
|
|
"plugin:dialog|open": () => picked,
|
|
"plugin:dialog|message": () => "Cancel",
|
|
workspace_new: args => {
|
|
if (args.name === "Existing") throw "A file or folder with that name already exists.";
|
|
const root = args.parent + "\\" + args.name;
|
|
recent = [root, ...recent]; windows.push(root);
|
|
},
|
|
workspace_open_window: args => {
|
|
if (args.path.endsWith("Missing")) throw "folder does not exist";
|
|
windows.push(args.path);
|
|
recent = [args.path, ...recent.filter(p => p !== args.path)];
|
|
},
|
|
workspace_open: args => {
|
|
if (args.path.endsWith("Missing")) throw "folder does not exist";
|
|
current = args.path; recent = [current, ...recent.filter(p => p !== current)];
|
|
return { root: current, name: current.split("\\").pop(), watch_mode: "native" };
|
|
},
|
|
};
|
|
},
|
|
});
|
|
await page.goto(smokeUrl);
|
|
await page.locator(".ws").filter({ hasText: "Notes" }).waitFor();
|
|
await page.keyboard.press("Control+p");
|
|
await page.getByRole("textbox", { name: "Find a file" }).fill("note.txt");
|
|
await page.getByRole("dialog").getByRole("button").filter({ hasText: "note.txt" }).first().click();
|
|
await page.locator(".source-editor .cm-content").waitFor();
|
|
await page.evaluate(async () => {
|
|
window.__EditorView = (await import("/node_modules/@codemirror/view/dist/index.js")).EditorView;
|
|
const view = window.__EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"));
|
|
view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: "My pending edit" } });
|
|
});
|
|
const trigger = page.getByRole("button", { name: "Open folder", exact: true });
|
|
const menu = page.getByRole("dialog", { name: "Workspaces", exact: true });
|
|
await page.evaluate(() => window.__TEST__.reorder());
|
|
await trigger.click();
|
|
await menu.getByText("D:\\Writing\\Notes", { exact: true }).waitFor();
|
|
await page.mouse.move(1000, 50);
|
|
assert.equal(await menu.locator('.workspace-row').first().evaluate(node => node === document.activeElement), false, "Pointer opening does not force focus onto a different workspace");
|
|
assert.equal(await menu.locator('.workspace-row').first().evaluate(node => getComputedStyle(node).backgroundColor), "rgba(0, 0, 0, 0)", "The first workspace has no stuck highlight");
|
|
assert.equal(await menu.locator('[aria-current="true"]').count(), 1);
|
|
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "plugin:dialog|open").length), 0);
|
|
await page.screenshot({ path: path.join(output, "workspaces-menu.png") });
|
|
const opened = await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "workspace_open").length);
|
|
await menu.getByRole("button").filter({ hasText: "Current" }).click();
|
|
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "workspace_open").length), opened);
|
|
await page.keyboard.press("Control+o");
|
|
await menu.getByRole("button").filter({ hasText: "Missing" }).click();
|
|
await menu.getByRole("alert").filter({ hasText: "folder does not exist" }).waitFor();
|
|
await menu.getByRole("button", { name: "Open another folder…" }).click();
|
|
assert(await menu.isVisible(), "Cancelling folder picker keeps history available");
|
|
await menu.getByRole("button").filter({ hasText: "D:\\Writing\\Notes" }).click();
|
|
await menu.waitFor({ state: "hidden" });
|
|
assert.equal(await page.locator(".ws").textContent(), "Notes");
|
|
assert.deepEqual(await page.evaluate(() => window.__TEST__.windows), ["D:\\Writing\\Notes"]);
|
|
await trigger.click();
|
|
await page.evaluate(() => window.__TEST__.pick("D:\\Other"));
|
|
await menu.getByRole("button", { name: "Open another folder…" }).click();
|
|
await menu.waitFor({ state: "hidden" });
|
|
assert.equal(await page.locator(".ws").textContent(), "Notes");
|
|
await trigger.click();
|
|
await menu.getByRole("button", { name: "New workspace…" }).click();
|
|
const dialog = page.getByRole("dialog", { name: "New workspace", exact: true });
|
|
assert(await dialog.getByRole("button", { name: "Create workspace", exact: true }).isDisabled());
|
|
await dialog.getByLabel("Workspace name").fill("Existing");
|
|
await page.evaluate(() => window.__TEST__.pick("D:\\Projects"));
|
|
await dialog.getByRole("button", { name: "Browse…" }).click();
|
|
await dialog.getByRole("button", { name: "Create workspace", exact: true }).click();
|
|
await dialog.getByRole("alert").filter({ hasText: "already exists" }).waitFor();
|
|
await dialog.getByLabel("Workspace name").fill("Fresh notes");
|
|
await page.screenshot({ path: path.join(output, "workspaces-create.png") });
|
|
await dialog.getByRole("button", { name: "Create workspace", exact: true }).click();
|
|
await dialog.waitFor({ state: "hidden" });
|
|
assert.equal(await page.locator(".ws").textContent(), "Notes");
|
|
assert.deepEqual(await page.evaluate(() => window.__TEST__.windows), ["D:\\Writing\\Notes", "D:\\Other", "D:\\Projects\\Fresh notes"]);
|
|
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "workspace_open").length), opened);
|
|
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "plugin:dialog|message").length), 0);
|
|
assert.equal(await page.evaluate(() => window.__EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"))?.state.doc.toString()), "My pending edit");
|
|
assert(await page.getByRole("tab", { name: /note\.txt/ }).isVisible());
|
|
await trigger.click();
|
|
await page.keyboard.press("End");
|
|
assert.equal(await page.locator(":focus").textContent(), " Open another folder…");
|
|
await page.keyboard.press("Escape");
|
|
await menu.waitFor({ state: "hidden" });
|
|
for (const theme of ['light', 'dark']) {
|
|
await page.evaluate(async mode => {
|
|
const { applyAppearance } = await import('/src/lib/theme/appearance.ts');
|
|
applyAppearance({ theme: 'default', mode });
|
|
}, theme);
|
|
await page.setViewportSize({ width: theme === 'light' ? 1100 : 380, height: 800 });
|
|
await trigger.click();
|
|
await menu.getByRole('button', { name: 'Remove D:\\Missing from recent workspaces', exact: true }).focus();
|
|
await page.screenshot({ path: path.join(output, `workspaces-remove-${theme}.png`) });
|
|
if (theme === 'dark') {
|
|
await page.keyboard.press('Enter');
|
|
await menu.getByText('D:\\Missing', { exact: true }).waitFor({ state: 'detached' });
|
|
assert.equal(await page.locator('.ws').textContent(), 'Notes', 'History removal does not close the current workspace');
|
|
await page.keyboard.press('Escape');
|
|
await trigger.click();
|
|
assert.equal(await menu.getByText('D:\\Missing', { exact: true }).count(), 0, 'Removed paths stay absent after reopening');
|
|
}
|
|
await page.keyboard.press('Escape');
|
|
}
|
|
await page.setViewportSize({ width: 1100, height: 800 });
|
|
await page.evaluate(() => window.__TEST__.clear());
|
|
await trigger.click();
|
|
await menu.getByText("No recent workspaces yet.").waitFor();
|
|
await page.getByRole("button", { name: "New tab (Ctrl T)", exact: true }).click();
|
|
await menu.waitFor({ state: "hidden" });
|
|
console.log("Workspace smoke passed: history, opening and creating in new windows, original workspace preserved, cancellation, errors, keyboard and empty state.");
|
|
}, { viewport: { width: 1100, height: 800 }, timeout: 30000 });
|