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:
@@ -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`) });
|
||||
|
||||
Reference in New Issue
Block a user