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
+18 -33
View File
@@ -1,4 +1,4 @@
// Editor menu surfaces: Writer, spelling, IDE, and code menus share the file menu styles; code tint and the command palette match in both themes.
// Editor menu surfaces: Writer, spelling, IDE, and code menus share the file menu styles; and the code tint match in both themes.
import assert from "node:assert/strict";
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
@@ -93,59 +93,44 @@ await runSmoke("editor/surfaces", async ({ page }) => {
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('.monaco-host').click({ button: 'right', position: { x: 500, y: 400 } });
await page.locator('.source-editor .cm-content').waitFor();
await page.locator('.source-editor').click({ button: 'right', position: { x: 500, y: 400 } });
assert.deepEqual(await styles(writer), reference, 'Markdown IDE retains the same menu');
await dismiss();
await page.locator('[data-tree-rel="sample.txt"]').click();
await page.locator('.monaco-host').click({ button: 'right', position: { x: 500, y: 400 } });
await page.locator('.source-editor').click({ button: 'right', position: { x: 500, y: 400 } });
const code = menu('Code text actions');
assert.deepEqual(await styles(code), reference, 'Code IDE uses the host menu');
assert.equal(await page.locator('.monaco-menu').count(), 0);
// The host menu is the only menu. The editor adds no menu of its own.
assert.equal(await page.getByRole('menu').count(), 1);
assert.equal(await code.getByRole('menuitem', { name: 'Command palette F1', exact: true }).count(), 0);
await page.screenshot({ path: `${output}/ide-menu-${theme}.png` });
await page.getByRole('menuitem', { name: 'Command palette F1', exact: true }).click();
const palette = page.locator('.quick-input-widget');
await palette.waitFor({ state: 'visible' });
const paletteMetrics = () => palette.evaluate(node => {
const row = node.querySelector('.monaco-list-row.focused');
const field = node.querySelector('.monaco-inputbox');
const a = getComputedStyle(row), b = getComputedStyle(field);
const probe = document.createElement('div');
probe.style.background = 'var(--rs-item-selection-bg)'; probe.style.color = 'var(--rs-item-selection-border)';
node.append(probe); const expected = getComputedStyle(probe);
const result = { fill: a.backgroundColor, expectedFill: expected.backgroundColor, outline: a.outlineColor, expectedOutline: expected.color, radius: a.borderRadius, inputRadius: b.borderRadius, inputOutline: b.outlineColor, inputOutlineWidth: b.outlineWidth };
probe.remove(); return result;
});
let p = await paletteMetrics();
assert.equal(p.fill, p.expectedFill);
assert.equal(p.outline, p.expectedOutline);
assert.equal(p.radius, '5px'); assert.equal(p.inputRadius, '5px');
assert.equal(p.inputOutline, p.expectedOutline); assert.equal(p.inputOutlineWidth, '2px');
await page.keyboard.press('ArrowDown');
p = await paletteMetrics(); assert.equal(p.fill, p.expectedFill);
await page.screenshot({ path: `${output}/palette-${theme}.png` });
await page.keyboard.press('Escape');
await dismiss();
await page.getByRole('button', { name: 'Files', exact: true }).click();
await page.getByRole('button', { name: 'Hide outline', exact: true }).click();
await page.setViewportSize({ width: 560, height: 620 });
await page.locator('.monaco-host').click({ button: 'right', position: { x: 100, y: 300 } });
await page.locator('.source-editor').click({ button: 'right', position: { x: 100, y: 300 } });
await code.waitFor();
const bounds = await code.boundingBox();
assert.ok(bounds.x >= 0 && bounds.x + bounds.width <= 560);
await page.keyboard.press('End');
assert.equal(await page.getByRole('menuitem', { name: 'Command palette F1', exact: true }).evaluate(n => n === document.activeElement), true);
assert.equal(await page.getByRole('menuitem', { name: 'Select all Ctrl+A', exact: true }).evaluate(n => n === document.activeElement), true);
await page.screenshot({ path: `${output}/ide-narrow-${theme}.png` });
await page.keyboard.press('Enter');
await palette.waitFor({ state: 'visible' });
await page.screenshot({ path: `${output}/palette-narrow-${theme}.png` });
await page.keyboard.press('Escape');
await code.waitFor({ state: 'detached' });
// The keyboard choice runs the action: the selection covers the whole file.
assert.equal(await 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.state.selection.main.from === 0 && view.state.selection.main.to === view.state.doc.length;
}), true);
await page.setViewportSize({ width: 1440, height: 1000 });
await page.getByRole('button', { name: 'Files', exact: true }).click();
await page.getByRole('button', { name: 'Show outline', exact: true }).click();
await page.locator('[data-tree-rel="a.md"]').click();
await page.getByRole('group', { name: 'Editor layout', exact: true }).hover();
await page.getByRole('button', { name: 'Writer', exact: true }).click();
report.push({ theme, passed: ['word and blank menu parity', 'spelling correction and undo', 'Writer/IDE parity', 'undo menu action', 'code menu host styles', 'transparent code in Writer/Reader', 'palette selection/focus', 'narrow keyboard menu/palette'], nativeDesktop: 'not tested' });
report.push({ theme, passed: ['word and blank menu parity', 'spelling correction and undo', 'Writer/IDE parity', 'undo menu action', 'code menu host styles', 'transparent code in Writer/Reader', 'narrow keyboard menu'], nativeDesktop: 'not tested' });
}
console.log(JSON.stringify(report, null, 2));
}, { timeout: 15000 });