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
+15 -14
View File
@@ -36,17 +36,17 @@ await runSmoke("find/documentFind", async ({ page }) => {
}
async function onePanel() {
assert.equal(await page.locator('.rs-find-bar:visible').count(), 1);
assert.equal(await page.locator('.find-widget.visible').count(), 0, 'No Monaco floating find widget');
assert.equal(await page.locator('.cm-search').count(), 0, 'No default CodeMirror search panel');
const bar = await page.locator('.rs-find-bar:visible').boundingBox();
const pane = await page.locator('.editor.pane-active').boundingBox();
assert.ok(Math.abs(bar.width - pane.width) < 3, 'Find spans the document pane');
}
async function sourceEditor() {
await page.waitForFunction(() => !!document.querySelector('.monaco-editor'));
await page.waitForFunction(() => !!document.querySelector('.source-editor .cm-content'));
return page.evaluate(async () => {
const { monaco } = await import('/src/lib/editor/monacoEnv.ts');
window.__MONACO__ = monaco.editor.getEditors().find(view => view.getDomNode()?.isConnected && view.getDomNode().getBoundingClientRect().width > 0);
window.__MONACO__.focus();
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
window.__SOURCE__ = EditorView.findFromDOM(document.querySelector('.source-editor .cm-content'));
window.__SOURCE__.focus();
});
}
await page.goto(smokeUrl);
@@ -84,21 +84,22 @@ await runSmoke("find/documentFind", async ({ page }) => {
await page.keyboard.press('Escape');
await mode('Editor layout', 'IDE');
await sourceEditor();
await page.evaluate(() => { window.__MONACO__.getModel().setValue('Alpha alpha alphabet\r\nAlpha second\r\nAlpha third'); window.__MONACO__.setPosition({ lineNumber: 1, column: 1 }); });
await page.evaluate(() => { const view = window.__SOURCE__; view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: 'Alpha alpha alphabet\r\nAlpha second\r\nAlpha third' }, selection: { anchor: 0 } }); });
await page.keyboard.press('Control+f');
await find.fill('Alpha');
await onePanel();
await page.keyboard.press('Enter');
const first = await page.evaluate(() => window.__MONACO__.getSelection().toString());
const selection = () => page.evaluate(() => JSON.stringify(window.__SOURCE__.state.selection.main));
const first = await selection();
await page.keyboard.press('Enter');
assert.notEqual(await page.evaluate(() => window.__MONACO__.getSelection().toString()), first);
assert.notEqual(await selection(), first);
await page.keyboard.press('Shift+Enter');
assert.equal(await page.evaluate(() => window.__MONACO__.getSelection().toString()), first);
assert.equal(await selection(), first);
await page.getByRole('checkbox', { name: 'Match case' }).check();
await page.getByRole('checkbox', { name: 'Whole word' }).check();
await replace.fill('Gamma');
await page.getByRole('button', { name: 'Replace all', exact: true }).click();
assert.equal(await page.evaluate(() => window.__MONACO__.getValue().replace(/\r\n/g, '\n')), 'Gamma alpha alphabet\nGamma second\nGamma third');
assert.equal(await page.evaluate(() => window.__SOURCE__.state.doc.toString()), 'Gamma alpha alphabet\nGamma second\nGamma third');
await page.getByRole('checkbox', { name: 'Regex' }).check();
await find.fill('[');
assert.equal(await find.getAttribute('aria-invalid'), 'true');
@@ -107,15 +108,15 @@ await runSmoke("find/documentFind", async ({ page }) => {
await page.getByRole('checkbox', { name: 'Whole word' }).uncheck();
await replace.fill('$1!');
await page.getByRole('button', { name: 'Replace all', exact: true }).click();
assert.match(await page.evaluate(() => window.__MONACO__.getValue()), /^Gamma! alpha/);
assert.match(await page.evaluate(() => window.__SOURCE__.state.doc.toString()), /^Gamma! alpha/);
await page.getByRole('checkbox', { name: 'Regex' }).uncheck();
await find.fill('Gamma');
await page.getByRole('button', { name: 'Select all', exact: true }).click();
assert.equal(await page.evaluate(() => window.__MONACO__.getSelections().length), 3);
assert.equal(await page.evaluate(() => window.__SOURCE__.state.selection.ranges.length), 3);
await page.screenshot({ path: `${output}/source-${theme}.png` });
await find.focus(); await page.keyboard.press('Escape');
assert.equal(await find.count(), 0);
assert.equal(await page.evaluate(() => window.__MONACO__.hasTextFocus()), true);
assert.equal(await page.evaluate(() => window.__SOURCE__.hasFocus), true);
await page.keyboard.press('Control+h');
assert.equal(await replace.evaluate(node => node === document.activeElement), true);
await find.fill('Gamma');
@@ -128,7 +129,7 @@ await runSmoke("find/documentFind", async ({ page }) => {
await page.screenshot({ path: `${output}/source-narrow-${theme}.png` });
await page.setViewportSize({ width: 1440, height: 1000 });
await find.focus(); await page.keyboard.press('Escape');
await page.evaluate(sample => window.__MONACO__.getModel().setValue(sample), sample);
await page.evaluate(sample => { const view = window.__SOURCE__; view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: sample } }); }, sample);
await mode('Document view', 'Read');
await page.locator('.reading').focus();
await page.keyboard.press('Control+f');