Replace Monaco with one CodeMirror editor and nest list items with Tab
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.
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
// List nesting: Tab and Shift+Tab in Write, nested labels in Write and Read, one undo history in Write and Source, and the 4-space indent in Source.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/listNesting", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => ({
|
||||
...test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
files: {
|
||||
"notes/readme.md": "# Requirements\n\n1. Topic\n2. \n3. A\n",
|
||||
"src/hello.py": "print('hello')\n",
|
||||
},
|
||||
}),
|
||||
spelling_menu_install: () => null,
|
||||
}),
|
||||
});
|
||||
const output = await outputDir("editor/listNesting");
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText("smoke-workspace", { exact: true }).waitFor();
|
||||
async function open(name, editor) {
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
|
||||
await page.getByRole("textbox", { name: editor, exact: true }).waitFor();
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
});
|
||||
}
|
||||
const doc = () => page.evaluate(() => window.__CM__.state.doc.toString());
|
||||
const caretAt = (text, offset = text.length) => page.evaluate(([text, offset]) => {
|
||||
window.__CM__.dispatch({ selection: { anchor: window.__CM__.state.doc.toString().indexOf(text) + offset } });
|
||||
window.__CM__.focus();
|
||||
}, [text, offset]);
|
||||
const labels = () => page.locator(".live-writer .writer-list-label").allTextContents();
|
||||
|
||||
await open("readme.md", "Writing editor");
|
||||
await caretAt("2. ");
|
||||
await page.keyboard.press("Tab");
|
||||
assert.equal(await doc(), "# Requirements\n\n1. Topic\n 1. \n2. A\n", "Tab nests the empty item and renumbers the next item");
|
||||
assert.deepEqual(await labels(), ["a."], "The nested item shows a letter before it has text");
|
||||
await page.keyboard.type("Sub item");
|
||||
await page.keyboard.press("Enter");
|
||||
await page.keyboard.type("Second");
|
||||
assert.equal(await doc(), "# Requirements\n\n1. Topic\n 1. Sub item\n 2. Second\n2. A\n");
|
||||
assert.deepEqual(await labels(), ["a.", "b."]);
|
||||
for (const width of [1440, 600]) {
|
||||
if (width === 600) {
|
||||
await page.getByRole("button", { name: "Files", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Hide outline", exact: true }).click();
|
||||
}
|
||||
await page.setViewportSize({ width, height: 800 });
|
||||
for (const mode of ["dark", "light"]) {
|
||||
await page.evaluate(async mode => (await import("/src/lib/theme/appearance.ts")).saveAppearance({ theme: "default", mode }), mode);
|
||||
await page.locator(".live-writer .cm-content").screenshot({ path: `${output}/writer-${mode}-${width}.png` });
|
||||
}
|
||||
}
|
||||
await page.setViewportSize({ width: 1440, height: 900 });
|
||||
await page.locator(".live-writer .cm-content").focus();
|
||||
|
||||
await page.keyboard.press("Shift+Tab");
|
||||
assert.equal(await doc(), "# Requirements\n\n1. Topic\n 1. Sub item\n2. Second\n3. A\n", "Shift+Tab moves the item up and renumbers the outer list");
|
||||
assert.deepEqual(await labels(), ["a."]);
|
||||
await page.keyboard.press("Control+z");
|
||||
assert.equal(await doc(), "# Requirements\n\n1. Topic\n 1. Sub item\n 2. Second\n2. A\n", "One undo step restores the nesting and the numbers");
|
||||
await caretAt("1. Topic");
|
||||
await page.keyboard.press("Tab");
|
||||
assert.equal(await doc(), "# Requirements\n\n1. Topic\n 1. Sub item\n 2. Second\n2. A\n", "The first item stays in place");
|
||||
|
||||
await page.getByRole("group", { name: "Document view" }).hover();
|
||||
await page.getByRole("button", { name: "Read", exact: true }).click();
|
||||
await page.locator(".md-page ol ol").waitFor();
|
||||
assert.equal(await page.locator(".md-page ol ol").evaluate(list => getComputedStyle(list).listStyleType), "lower-alpha");
|
||||
assert.equal(await page.locator(".md-page > .reading > ol, .md-page ol").first().evaluate(list => getComputedStyle(list).listStyleType), "decimal");
|
||||
await page.locator(".md-page").screenshot({ path: `${output}/reader.png` });
|
||||
await page.getByRole("group", { name: "Document view" }).hover();
|
||||
await page.getByRole("button", { name: "Edit", exact: true }).click();
|
||||
await page.getByRole("textbox", { name: "Writing editor", exact: true }).waitFor();
|
||||
|
||||
// Write and Source share the undo history of the document.
|
||||
await caretAt("2. A");
|
||||
await page.keyboard.type(" more");
|
||||
await page.keyboard.press("Control+e");
|
||||
await page.locator('.source-editor[data-chrome="Ide"] .cm-gutters').waitFor();
|
||||
assert.equal(await page.locator(".source-editor .cm-content").getAttribute("data-language"), "markdown");
|
||||
await page.locator(".source-editor .cm-content").focus();
|
||||
await page.keyboard.press("Control+z");
|
||||
assert.equal(await doc(), "# Requirements\n\n1. Topic\n 1. Sub item\n 2. Second\n2. A\n", "Source undoes the last edit from Write");
|
||||
await page.keyboard.press("Control+Shift+KeyZ");
|
||||
assert.equal(await doc(), "# Requirements\n\n1. Topic\n 1. Sub item\n 2. Second\n2. A more\n");
|
||||
await caretAt("2. A more");
|
||||
await page.keyboard.press("Tab");
|
||||
assert.equal(await doc(), "# Requirements\n\n1. Topic\n 1. Sub item\n 2. Second\n 3. A more\n", "Tab nests list items in Source too");
|
||||
await page.keyboard.press("Control+e");
|
||||
await page.getByRole("textbox", { name: "Writing editor", exact: true }).waitFor();
|
||||
assert.deepEqual(await labels(), ["a.", "b.", "c."]);
|
||||
|
||||
// Source indents code to the next 4-column stop.
|
||||
await open("hello.py", "Editor");
|
||||
await caretAt("print", 0);
|
||||
await page.keyboard.press("Tab");
|
||||
assert.equal(await doc(), " print('hello')\n");
|
||||
await caretAt("print", 2);
|
||||
await page.keyboard.press("Tab");
|
||||
assert.equal(await doc(), " pr int('hello')\n", "Tab inside a line fills to the next stop");
|
||||
await page.keyboard.press("Control+z");
|
||||
await page.keyboard.press("Control+z");
|
||||
assert.equal(await doc(), "print('hello')\n");
|
||||
await page.locator(".source-editor").screenshot({ path: `${output}/source-ide.png` });
|
||||
|
||||
// The history of a document stays while its tab stays open.
|
||||
await open("readme.md", "Writing editor");
|
||||
await page.locator(".live-writer .cm-content").focus();
|
||||
await page.keyboard.press("Control+z");
|
||||
assert.equal(await doc(), "# Requirements\n\n1. Topic\n 1. Sub item\n 2. Second\n2. A more\n", "Undo after a tab change reverts the Tab from Source");
|
||||
console.log("PASS: Tab and Shift+Tab nesting, renumbering, Write labels, Read letters, shared undo in Write and Source and across tabs, Source list Tab, and 4-space code indent.");
|
||||
});
|
||||
Reference in New Issue
Block a user