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
@@ -102,13 +102,13 @@ await runSmoke('appearance/backgroundFrames', async ({ browser }) => {
assert.deepEqual(await background.boundingBox(), beforeScroll);
await page.screenshot({ path: `${output}/${theme}-reader.png` });
await page.getByRole('button', { name: 'Split', exact: true }).click();
await page.locator('.monaco-editor').waitFor();
assert.equal(await style(page.locator('.monaco-editor-background').first(), 'backgroundColor'), 'rgba(0, 0, 0, 0)');
await page.locator('.source-editor .cm-content').waitFor();
assert.equal(await style(page.locator('.source-editor .cm-editor').first(), 'backgroundColor'), 'rgba(0, 0, 0, 0)');
await page.screenshot({ path: `${output}/${theme}-split.png` });
await page.getByRole('button', { name: 'Edit', exact: true }).click();
await page.getByRole('group', { name: 'Editor layout', exact: true }).hover();
await page.getByRole('button', { name: 'IDE', exact: true }).click();
await page.locator('.monaco-editor').waitFor();
await page.locator('.source-editor .cm-content').waitFor();
await page.screenshot({ path: `${output}/${theme}-ide.png` });
await page.setViewportSize({ width: 680, height: 720 });
await page.getByRole('button', { name: 'Files', exact: true }).click();
@@ -37,11 +37,10 @@ await runSmoke('appearance/characterThemes', async ({ browser }) => {
await openFile(main, 'Theme.md');
await main.getByRole('textbox', { name: 'Writing editor', exact: true }).waitFor();
await openFile(ide, 'Theme.py');
await ide.locator('.monaco-editor textarea').waitFor();
const editorIds = () => ide.evaluate(async () => {
const { monaco } = await import('/src/lib/editor/monacoEnv.ts');
return monaco.editor.getEditors().filter(editor => editor.getDomNode()?.isConnected).map(editor => editor.getId());
});
await ide.locator('.source-editor .cm-content').waitFor();
// Mark each mounted editor once. A new editor has no mark, so it gets a new identifier.
const editorIds = () => ide.evaluate(() => [...document.querySelectorAll('.source-editor .cm-editor')]
.map(node => node.dataset.smokeId ||= String(window.__editorSerial = (window.__editorSerial || 0) + 1)));
const initialEditors = await editorIds();
const openSettings = async () => {
await settings.goto(`${smokeUrl}/?settingsWindow=true`);
@@ -108,7 +107,7 @@ await runSmoke('appearance/characterThemes', async ({ browser }) => {
await settings.waitForFunction(() => window.exportedTheme);
assert.deepEqual(await settings.evaluate(() => window.exportedTheme), template);
await ide.waitForFunction(expected => {
const spans = [...document.querySelectorAll('.view-line span')].filter(node => !node.children.length);
const spans = [...document.querySelectorAll('.source-editor .cm-line span')].filter(node => !node.children.length);
return Object.entries(expected).every(([text, color]) => {
const node = spans.find(node => node.textContent.replaceAll('\u00a0', ' ').includes(text));
const probe = document.createElement('i');
@@ -116,7 +115,7 @@ await runSmoke('appearance/characterThemes', async ({ browser }) => {
const target = getComputedStyle(probe).color; probe.remove();
return node && getComputedStyle(node).color === target;
});
}, { return: colors['syntax-keyword'], RuneStone: colors['syntax-string'], 42: colors['syntax-number'], print: colors['syntax-keyword'], '# Character colors': colors['syntax-comment'] });
}, { return: colors['syntax-keyword'], RuneStone: colors['syntax-string'], 42: colors['syntax-number'], print: colors['syntax-function'], '# Character colors': colors['syntax-comment'] });
assert.deepEqual(await editorIds(), initialEditors, 'Theme changes preserve the editor');
if (theme === 'harvest-moon') {
const normalized = await settings.evaluate(async () => {
@@ -147,17 +146,17 @@ await runSmoke('appearance/characterThemes', async ({ browser }) => {
assert.equal(await main.evaluate(() => window.getSelection().toString()), 'A calm surface with readable text.');
await main.screenshot({ path: path.join(output, `${theme}-${mode}-writer-selection.png`) });
await ide.evaluate(async () => {
const { monaco } = await import('/src/lib/editor/monacoEnv.ts');
const editor = monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected);
editor.setSelection(new monaco.Selection(1, 1, 3, 21)); editor.focus();
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
const view = EditorView.findFromDOM(document.querySelector('.source-editor .cm-content'));
view.dispatch({ selection: { anchor: 0, head: view.state.doc.line(3).from + 20 } }); view.focus();
});
await ide.locator('.selected-text').first().waitFor();
assert.equal(await ide.locator('.selected-text').first().evaluate(node => getComputedStyle(node).backgroundColor),
await ide.locator('.source-editor .cm-selectionBackground').first().waitFor();
assert.equal(await ide.locator('.source-editor .cm-selectionBackground').first().evaluate(node => getComputedStyle(node).backgroundColor),
warmFill, 'IDE selection uses the same warm fill');
await ide.screenshot({ path: path.join(output, `${theme}-${mode}-ide-selection.png`) });
await ide.evaluate(async () => {
const { monaco } = await import('/src/lib/editor/monacoEnv.ts');
monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected).setPosition({ lineNumber: 1, column: 1 });
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
EditorView.findFromDOM(document.querySelector('.source-editor .cm-content')).dispatch({ selection: { anchor: 0 } });
});
}
await ide.screenshot({ path: path.join(output, `${theme}-${mode}-ide.png`) });
+1 -1
View File
@@ -75,7 +75,7 @@ await runSmoke("appearance/density", async ({ page }) => {
await documentView().press("Home");
}
await editorLayout().press("Home");
await page.locator(".monaco-editor").waitFor();
await page.locator(".source-editor .cm-content").waitFor();
await page.locator(".line-history").waitFor();
await page.evaluate(() => window.removeGit());
await page.locator(".line-history").waitFor({ state: "hidden" });
+16 -19
View File
@@ -1,4 +1,4 @@
// Built-in palettes: modes, light-only Sakura, migration, persistence, typography, cross-window sync, Monaco updates, and narrow settings.
// Built-in palettes: modes, light-only Sakura, migration, persistence, typography, cross-window sync, source editor updates, and narrow settings.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
@@ -28,24 +28,21 @@ await runSmoke("appearance/palettes", async ({ browser }) => {
await main.getByRole("textbox", { name: "Find a file" }).fill(`theme-${index}.py`);
await main.getByRole("dialog").getByRole("button").filter({ hasText: `theme-${index}.py` }).first().waitFor();
await main.getByRole("textbox", { name: "Find a file" }).press("Enter");
await main.locator(".monaco-editor textarea").waitFor();
await main.waitForFunction(async file => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
return monaco.editor.getEditors().some(editor => editor.getDomNode()?.isConnected && editor.getModel()?.uri.path.endsWith(file));
}, `theme-${index}.py`);
await main.locator(".view-line").filter({ hasText: `Theme sample ${index}` }).waitFor();
await main.locator(".source-editor .cm-content").waitFor();
await main.waitForFunction(file => document.querySelector(".editor .breadcrumb")?.textContent.endsWith(file)
&& document.querySelector(".source-editor .cm-content")?.dataset.language === "python", `theme-${index}.py`);
await main.locator(".source-editor .cm-line").filter({ hasText: `Theme sample ${index}` }).waitFor();
}
async function editorIds() {
return main.evaluate(async () => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
return monaco.editor.getEditors().filter(editor => editor.getDomNode()?.isConnected).map(editor => editor.getId());
});
// Mark each mounted editor once. A new editor has no mark, so it gets a new identifier.
return main.evaluate(() => [...document.querySelectorAll(".source-editor .cm-editor")]
.map(node => node.dataset.smokeId ||= String(window.__editorSerial = (window.__editorSerial || 0) + 1)));
}
// Wait until "RuneStone", "print", and "42" have three distinct syntax colors.
// Wait until "RuneStone", "def", and "42" have three distinct syntax colors.
async function waitForSyntax() {
await main.waitForFunction(() => {
const spans = [...document.querySelectorAll(".view-line span")];
const colors = ["RuneStone", "print", "42"].map(text => {
const spans = [...document.querySelectorAll(".source-editor .cm-line span")];
const colors = ["RuneStone", "def", "42"].map(text => {
const span = spans.find(node => !node.children.length && node.textContent.includes(text));
return span ? getComputedStyle(span).color : null;
});
@@ -79,7 +76,7 @@ await runSmoke("appearance/palettes", async ({ browser }) => {
document.body.append(probe);
const expected = getComputedStyle(probe).backgroundColor;
probe.remove();
const surfaces = [...document.querySelectorAll(".monaco-editor .monaco-editor-background")];
const surfaces = [...document.querySelectorAll(".source-editor .cm-editor")];
const workarea = document.querySelector(".editor > .body");
return surfaces.length > 0 && surfaces.every(element => getComputedStyle(element).backgroundColor === "rgba(0, 0, 0, 0)")
&& workarea && getComputedStyle(workarea).backgroundColor === expected;
@@ -94,16 +91,16 @@ await runSmoke("appearance/palettes", async ({ browser }) => {
const before = await editorIds();
await choose(settings, theme, mode);
backgrounds.add(await expectAppearance(theme, mode));
assert.deepEqual(await editorIds(), before, "Existing Monaco editors keep their identity when a theme changes");
assert.deepEqual(await editorIds(), before, "Existing source editors keep their identity when a theme changes");
await openCode(nextCode++);
assert.notDeepEqual(await editorIds(), before, "A new file creates a new Monaco editor");
assert.notDeepEqual(await editorIds(), before, "A new file creates a new source editor");
await expectAppearance(theme, mode);
await waitForSyntax();
assert.deepEqual(await settings.evaluate(() => window.__TEST__.settings("appearance")), { theme, mode });
await settings.screenshot({ path: path.join(output, `appearance-${theme}-${mode}.png`) });
await main.screenshot({ path: path.join(output, `appearance-editor-${theme}-${mode}.png`) });
if (theme === "sakura") {
const keywordColor = await main.locator(".view-line span").evaluateAll(spans => {
const keywordColor = await main.locator(".source-editor .cm-line span").evaluateAll(spans => {
const keyword = spans.find(span => !span.children.length && span.textContent.trim() === "def");
return keyword ? getComputedStyle(keyword).color : null;
});
@@ -120,7 +117,7 @@ await runSmoke("appearance/palettes", async ({ browser }) => {
assert.match(typography.heading, /Poppins.*Arial/);
assert.equal(await settings.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue("--rs-accent").trim()), "#d97757");
} else assert.doesNotMatch(typography.body, /Lora|Georgia/);
console.log(`PASS: ${theme} ${mode}, saved state, cross-window selection, existing and new Monaco editors`);
console.log(`PASS: ${theme} ${mode}, saved state, cross-window selection, existing and new source editors`);
}
}
assert.equal(backgrounds.size, 5, "All supported combinations have distinct backgrounds");