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
+1 -7
View File
@@ -1,7 +1,7 @@
import test from "node:test";
import assert from "node:assert/strict";
import { SearchQuery } from "@codemirror/search";
import { documentMatches, replacementText } from "../../../src/lib/editor/findTarget.ts";
import { documentMatches } from "../../../src/lib/editor/findTarget.ts";
test("document search uses Writer word matching and normalized CRLF positions", () => {
const query = new SearchQuery({ search: "Alpha", wholeWord: true, caseSensitive: true });
@@ -11,12 +11,6 @@ test("document search uses Writer word matching and normalized CRLF positions",
assert.equal(state.doc.lineAt(matches[1].from).from, 15);
});
test("replacement keeps regex context, capture groups, dollars, and line breaks", () => {
const query = new SearchQuery({ search: "(?<=G)(amma)", regexp: true, replace: "$1-$12-$&-$$\\n" });
assert.equal(replacementText("Gamma", 1, query), "amma-amma2-amma-$\n");
assert.equal(replacementText("Alpha", 0, new SearchQuery({ search: "Alpha", replace: "$1\\t" })), "$1\t");
});
test("empty and invalid queries do not produce matches", () => {
assert.deepEqual(documentMatches("Alpha", new SearchQuery({ search: "" })).matches, []);
assert.deepEqual(documentMatches("Alpha", new SearchQuery({ search: "[", regexp: true })).matches, []);
+90
View File
@@ -0,0 +1,90 @@
import assert from "node:assert/strict";
import test from "node:test";
import { EditorState } from "@codemirror/state";
import { indentUnit } from "@codemirror/language";
import { markdown, markdownLanguage } from "@codemirror/lang-markdown";
import { noteFormats } from "../../../src/lib/editor/noteFormats.ts";
import { indentListItems, listLabels, orderedLabel, outdentListItems } from "../../../src/lib/editor/markdownLists.ts";
const extensions = [markdown({ base: markdownLanguage, extensions: [noteFormats] }), indentUnit.of(" ")];
/** A document with `|` at the caret, or two `|` around a selection. */
function editor(marked: string) {
const anchor = marked.indexOf("|"), head = marked.indexOf("|", anchor + 1);
const doc = marked.replaceAll("|", "");
return EditorState.create({ doc, selection: { anchor, head: head < 0 ? anchor : head - 1 }, extensions });
}
function run(move: typeof indentListItems, marked: string) {
const state = editor(marked), specs = move(state);
if (!specs) return null;
const next = state.update(...specs).state;
const { from, to } = next.selection.main;
const doc = next.doc.toString();
return from === to ? doc.slice(0, from) + "|" + doc.slice(from) : doc.slice(0, from) + "|" + doc.slice(from, to) + "|" + doc.slice(to);
}
test("tab makes a nested list and renumbers the items after it", () => {
assert.equal(run(indentListItems, "1. Topic\n2. B|\n3. A"), "1. Topic\n 1. B|\n2. A");
});
test("tab on an empty item keeps the caret after its marker", () => {
assert.equal(run(indentListItems, "1. Topic\n2.|\n3. A"), "1. Topic\n 1.|\n2. A");
assert.equal(run(indentListItems, "1. Topic\n2. |\n3. A"), "1. Topic\n 1. |\n2. A");
});
test("tab adds the item to the nested list of the previous item", () => {
assert.equal(run(indentListItems, "1. A\n 1. x\n2. B|\n3. C"), "1. A\n 1. x\n 2. B|\n2. C");
});
test("tab moves the children of an item with it", () => {
assert.equal(run(indentListItems, "1. A\n2. B|\n 1. b\n3. C"), "1. A\n 1. B|\n 1. b\n2. C");
});
test("tab nests each selected item under the first unselected item", () => {
assert.equal(run(indentListItems, "1. A\n|2. B\n3. C|\n4. D"), "1. A\n| 1. B\n 2. C|\n2. D");
});
test("tab nests bullet items and keeps their marker", () => {
assert.equal(run(indentListItems, "- a\n- b|"), "- a\n - b|");
assert.equal(run(indentListItems, "- [ ] a\n- [x] b|"), "- [ ] a\n - [x] b|");
});
test("tab keeps the first item in place and ignores text outside lists", () => {
assert.deepEqual(indentListItems(editor("1. A|\n2. B")), []);
assert.equal(indentListItems(editor("Plain| text")), null);
assert.equal(indentListItems(editor("1. A\n\n ```\n co|de\n ```")), null);
});
test("shift+tab moves a nested item up and makes the later items its children", () => {
assert.equal(run(outdentListItems, "1. A\n 1. x\n 2. y|\n 3. z\n2. B"), "1. A\n 1. x\n2. y|\n 1. z\n3. B");
});
test("shift+tab gives the item the marker style of the outer list", () => {
assert.equal(run(outdentListItems, "1. A\n - x|\n2. B"), "1. A\n2. x|\n3. B");
assert.equal(run(outdentListItems, "- A\n 1. x|\n- B"), "- A\n- x|\n- B");
});
test("shift+tab keeps a top-level item in place", () => {
assert.deepEqual(outdentListItems(editor("1. A|\n2. B")), []);
assert.equal(outdentListItems(editor("Plain| text")), null);
});
test("ordered labels use numbers, letters, and Roman numerals by level", () => {
assert.equal(orderedLabel(1, 3), "3");
assert.equal(orderedLabel(2, 1), "a");
assert.equal(orderedLabel(2, 27), "aa");
assert.equal(orderedLabel(3, 4), "iv");
assert.equal(orderedLabel(4, 2), "2");
assert.equal(orderedLabel(2, 0), "0");
});
test("nested ordered markers get labels and the first level keeps its source", () => {
const state = editor("1. A\n 1. x\n 1. y\n 1. z\n2. B|");
assert.deepEqual(listLabels(state).map(label => [state.sliceDoc(label.from, label.to), label.label]), [["1.", "a."], ["1.", "b."], ["1.", "i."]]);
});
test("an empty nested marker gets its label before the item has text", () => {
const state = editor("1. Topic\n 1.\n2. A|");
assert.deepEqual(listLabels(state).map(label => label.label), ["a."]);
});
+5 -10
View File
@@ -1,7 +1,6 @@
import assert from "node:assert/strict";
import test from "node:test";
import { detectChrome, extensionOf, treeFileParts } from "../../../src/lib/workspace/chrome.ts";
import { monacoChrome } from "../../../src/lib/editor/monacoChrome.ts";
import { chromeLayout, detectChrome, extensionOf, treeFileParts } from "../../../src/lib/workspace/chrome.ts";
test("markdown files open in writing chrome", () => {
assert.equal(detectChrome("notes/inbox.md"), "Writing");
@@ -14,16 +13,12 @@ test("scripts open in ide chrome", () => {
assert.equal(detectChrome("Makefile"), "Ide");
});
test("writing chrome wraps and hides line numbers", () => {
assert.equal(monacoChrome("Writing").wordWrap, "on");
assert.equal(monacoChrome("Writing").lineNumbers, "off");
assert.equal(monacoChrome("Writing").minimap.enabled, false);
test("writing chrome wraps and hides the code gutters", () => {
assert.deepEqual(chromeLayout("Writing"), { wrap: true, gutters: false, activeLine: false });
});
test("ide chrome shows line numbers and no wrap", () => {
assert.equal(monacoChrome("Ide").wordWrap, "off");
assert.equal(monacoChrome("Ide").lineNumbers, "on");
assert.equal(monacoChrome("Ide").minimap.enabled, true);
test("ide chrome shows the code gutters and does not wrap", () => {
assert.deepEqual(chromeLayout("Ide"), { wrap: false, gutters: true, activeLine: true });
});
test("extensionOf reads the last suffix", () => {