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
+10 -10
View File
@@ -149,24 +149,24 @@ await runSmoke("editor/images", async ({ page }) => {
await page.getByRole("group", { name: "Document view" }).getByRole("button", { name: "Read", exact: true }).focus();
await page.keyboard.press("Home");
await page.keyboard.press("Control+e");
await page.locator(".monaco-editor textarea").waitFor();
await page.locator(".source-editor .cm-content").waitFor();
await page.evaluate(async () => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
window.__MONACO__ = monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected);
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
window.__CM__ = EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"));
});
const sourceBefore = await page.evaluate(() => window.__MONACO__.getValue());
await drop(2, ".monaco-editor .view-lines");
await page.waitForFunction(() => (window.__MONACO__.getValue().match(/!\[\]/g) || []).length === 5);
const sourceBefore = await source();
await drop(2, ".source-editor .cm-content");
await page.waitForFunction(() => (window.__CM__.state.doc.toString().match(/!\[\]/g) || []).length === 5);
await page.keyboard.press("Control+z");
assert.equal(await page.evaluate(() => window.__MONACO__.getValue()), sourceBefore);
assert.equal(await source(), sourceBefore);
await page.keyboard.press("Control+y");
assert.equal((await save()).match(/!\[\]/g).length, 5);
// A failed write leaves source unchanged and surfaces an error.
const beforeFailure = await page.evaluate(() => window.__MONACO__.getValue());
const beforeFailure = await source();
await page.evaluate(() => { window.__TEST__.failWrite = true; });
await drop(1, ".monaco-editor .view-lines");
await drop(1, ".source-editor .cm-content");
await page.getByText("Image write failed", { exact: true }).waitFor();
assert.equal(await page.evaluate(() => window.__MONACO__.getValue()), beforeFailure);
assert.equal(await source(), beforeFailure);
await page.evaluate(() => { window.__TEST__.failWrite = false; });
// File drops over a rendered widget are handled by the editor's capture listener.