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:
Knotty Wyvern
2026-10-28 10:48:44 -07:00
parent 80f5d908e0
commit 724402729e
70 changed files with 1583 additions and 1475 deletions
+6 -9
View File
@@ -44,9 +44,9 @@ await runSmoke("tree/newFiles", async ({ page }) => {
}
async function modelDetails() {
return page.evaluate(async () => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
const editor = monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected);
return editor && { language: editor.getModel().getLanguageId(), value: editor.getValue(), fontSize: editor.getOption(monaco.editor.EditorOption.fontSize) };
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) };
});
}
@@ -67,17 +67,14 @@ await runSmoke("tree/newFiles", async ({ page }) => {
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(".monaco-editor .view-line"));
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(async () => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
return monaco.editor.getEditors().some(editor => editor.getDomNode()?.isConnected && editor.getModel()?.getLanguageId() === "python");
});
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);
@@ -102,7 +99,7 @@ await runSmoke("tree/newFiles", async ({ page }) => {
return !event.defaultPrevented;
});
// Writer combines spelling suggestions with the Markdown actions (docs/design-decisions.md UI-027;
// src/lib/editor/LiveWriter.svelte:255-262 prevents the native menu and passes the spelling offset).
// 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();