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.
129 lines
6.9 KiB
JavaScript
129 lines
6.9 KiB
JavaScript
// New files keep exact names and extensions, renames change the code language, and Writer menus work in both themes.
|
|
import assert from "node:assert/strict";
|
|
import { mockTauri, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("tree/newFiles", async ({ page }) => {
|
|
await mockTauri(page, {
|
|
commands: test => {
|
|
const ws = test.workspace({
|
|
root: "C:\\editor-files-smoke",
|
|
files: {
|
|
"note.md": "Mispelled text.\n\n| Word | Value |\n| --- | --- |\n| Speling | Other |\n",
|
|
"hello.txt": "print('hello')\n",
|
|
"notes/existing.md": "Existing note",
|
|
},
|
|
});
|
|
const files = ws.files;
|
|
test.files = files;
|
|
return {
|
|
...ws,
|
|
workspace_list: args => ws.workspace_list(args).filter(entry => !entry.rel_path.startsWith(".runestone")),
|
|
workspace_create: ({ rel }) => {
|
|
if (files.has(rel)) throw new Error("path already exists");
|
|
files.set(rel, "");
|
|
},
|
|
workspace_rename: ({ from, to }) => {
|
|
if (files.has(to)) throw new Error("destination already exists");
|
|
files.set(to, files.get(from));
|
|
files.delete(from);
|
|
},
|
|
spelling_suggestions: ({ word }) => ({ language: "en-US", words: word === "Mispelled" ? ["Misspelled"] : [], misspelled: word === "Mispelled" }),
|
|
};
|
|
},
|
|
});
|
|
const row = name => page.locator(`[data-tree-rel="${name}"]`);
|
|
// The file pane header offers New note and New folder (src/lib/layout/FileTree.svelte:886-887);
|
|
// New file… is in the pane menu (src/lib/layout/FileTree.svelte:716-720).
|
|
async function newRootFile() {
|
|
await page.getByRole("navigation", { name: "Workspace files" }).click({ button: "right", position: { x: 80, y: 320 } });
|
|
await page.getByRole("menuitem", { name: "New file…", exact: true }).click();
|
|
}
|
|
async function enterName(name) {
|
|
await page.locator("#text-request").fill(name);
|
|
await page.getByRole("button", { name: "Continue", exact: true }).click();
|
|
}
|
|
async function modelDetails() {
|
|
return page.evaluate(async () => {
|
|
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
|
const view = EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"));
|
|
return view && { language: view.contentDOM.dataset.language, value: view.state.doc.toString(), fontSize: parseFloat(getComputedStyle(view.contentDOM).fontSize) };
|
|
});
|
|
}
|
|
|
|
await page.goto(smokeUrl);
|
|
await row("note.md").waitFor();
|
|
await newRootFile();
|
|
await enterName("LICENSE");
|
|
await row("LICENSE").waitFor();
|
|
await page.evaluate(() => window.__TEST__.files.set("LICENSE", "Keep this content"));
|
|
await newRootFile();
|
|
await enterName("LICENSE");
|
|
await page.getByText("path already exists", { exact: true }).waitFor();
|
|
assert.equal(await page.evaluate(() => window.__TEST__.files.get("LICENSE")), "Keep this content");
|
|
assert.equal(await page.evaluate(() => window.__TEST__.files.has("LICENSE 2")), false);
|
|
await row("notes").click({ button: "right" });
|
|
await page.getByRole("menuitem", { name: "New file…", exact: true }).click();
|
|
await enterName("hello_world.py");
|
|
await row("notes/hello_world.py").waitFor();
|
|
assert.equal(await page.evaluate(() => window.__TEST__.files.has("notes/hello_world.py.md")), false);
|
|
await row("hello.txt").dblclick();
|
|
await page.waitForFunction(() => !!document.querySelector(".source-editor .cm-line"));
|
|
await row("hello.txt").click({ button: "right" });
|
|
await page.getByRole("menuitem", { name: "Rename", exact: true }).click();
|
|
assert.equal(await row("hello.txt").locator("input.rename").inputValue(), "hello.txt");
|
|
await row("hello.txt").locator("input.rename").fill("hello.py");
|
|
await page.keyboard.press("Enter");
|
|
await row("hello.py").waitFor();
|
|
await page.waitForFunction(() => document.querySelector(".source-editor .cm-content")?.getAttribute("data-language") === "python");
|
|
const code = await modelDetails();
|
|
assert.equal(code.value, "print('hello')\n");
|
|
assert.equal(code.fontSize, 13);
|
|
await page.keyboard.press("Control+e");
|
|
assert.equal((await modelDetails()).fontSize, code.fontSize, "Code size stays the same in both layouts");
|
|
await row("note.md").dblclick();
|
|
await page.locator(".cm-content").waitFor();
|
|
await page.evaluate(async () => {
|
|
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
|
window.writerTest = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
|
});
|
|
for (const theme of ["dark", "light"]) {
|
|
await page.evaluate(async mode => {
|
|
const { saveAppearance } = await import("/src/lib/theme/appearance.ts");
|
|
saveAppearance({ theme: "default", mode });
|
|
}, theme);
|
|
const nativeAllowed = await page.evaluate(() => {
|
|
window.writerTest.dispatch({ selection: { anchor: 3 } });
|
|
const line = document.querySelector(".cm-line"), rect = line.getBoundingClientRect();
|
|
const event = new MouseEvent("contextmenu", { bubbles: true, cancelable: true, clientX: rect.left + 15, clientY: rect.top + 5 });
|
|
line.dispatchEvent(event);
|
|
return !event.defaultPrevented;
|
|
});
|
|
// Writer combines spelling suggestions with the Markdown actions (docs/design-decisions.md UI-027;
|
|
// the contextmenu handler of src/lib/editor/DocumentEditor.svelte prevents the native menu and passes the spelling offset).
|
|
assert.equal(nativeAllowed, false, "Plain text opens the shared Markdown menu instead of the native one");
|
|
const textMenu = page.getByRole("menu", { name: "Markdown text actions", exact: true });
|
|
await textMenu.getByRole("menuitem", { name: "Misspelled", exact: true }).waitFor();
|
|
await page.keyboard.press("Escape");
|
|
assert.equal(await page.getByRole("menu").count(), 0);
|
|
await page.evaluate(() => { window.writerTest.focus(); });
|
|
await page.keyboard.press("Shift+F10");
|
|
await page.getByRole("menu", { name: "Markdown text actions", exact: true }).waitFor();
|
|
await page.keyboard.press("Escape");
|
|
await page.evaluate(() => window.writerTest.dispatch({ selection: { anchor: 0, head: 9 } }));
|
|
await page.getByText("Mispelled text.", { exact: true }).click({ button: "right" });
|
|
await page.getByRole("menu", { name: "Markdown text actions", exact: true }).waitFor();
|
|
await page.keyboard.press("Escape");
|
|
await page.locator(".live-writer td").first().click({ button: "right" });
|
|
await page.getByRole("menu", { name: "Table actions", exact: true }).waitFor();
|
|
await page.keyboard.press("Escape");
|
|
await page.locator(".writer-cell-editor").click();
|
|
await page.keyboard.press("ArrowRight");
|
|
assert.equal(await page.locator(".writer-cell-editor p").evaluate(node => {
|
|
const event = new MouseEvent("contextmenu", { bubbles: true, cancelable: true });
|
|
node.dispatchEvent(event);
|
|
return !event.defaultPrevented;
|
|
}), true, "Active table text permits the native spelling menu");
|
|
await page.locator(".cm-line").first().click();
|
|
}
|
|
}, { viewport: { width: 1280, height: 900 }, timeout: 15000 });
|