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.
32 lines
2.1 KiB
TypeScript
32 lines
2.1 KiB
TypeScript
import { EditorState } from '@codemirror/state';
|
|
import { EditorView, keymap } from '@codemirror/view';
|
|
import { history, historyKeymap, defaultKeymap } from '@codemirror/commands';
|
|
import { completionExtension } from './codemirror';
|
|
import { completionHub } from './hub';
|
|
import { ExternalSession } from '../plugins/externalSession';
|
|
const editor = (parent: string, documentId: string) => new EditorView({ parent: document.querySelector(parent)!, state: EditorState.create({ doc: 'The ', selection: { anchor: 4 }, extensions: [history(), keymap.of([...historyKeymap, ...defaultKeymap]), completionExtension(documentId)] }) });
|
|
const writer = editor('#writer', 'fixture');
|
|
const source = editor('#source', 'fixture-source');
|
|
// Plugin browser tests read the source text through `model`.
|
|
const model = { getValue: () => source.state.doc.toString() };
|
|
let stopProvider = completionHub.registerProvider({ id: 'fixture', delayMs: 100, complete: async () => 'quiet harbor.' });
|
|
Object.assign(window, { completionTest: { writer, source, model, completionHub, stopProvider,
|
|
async plugin(code: string) {
|
|
stopProvider();
|
|
const session = new ExternalSession('test.autocomplete', {
|
|
settings: { read: async () => ({ enabled: true, endpoint: 'http://127.0.0.1:8012' }), write: async () => {} },
|
|
workspace: { list: async () => [], read: async () => '', write: async () => {} }, assets: { read: async () => new Uint8Array() },
|
|
completionTransport: async (request, signal, onLine) => {
|
|
if (request.route === '/v1/models') { onLine('{"data":[{"id":"fixture-model"}]}'); return; }
|
|
await new Promise(resolve => setTimeout(resolve, 25));
|
|
if (!signal.aborted) onLine('data: {"choices":[{"delta":{"content":"quiet harbor."}}]}\n');
|
|
},
|
|
}, () => {}, () => {});
|
|
const url = URL.createObjectURL(new Blob([code], { type: 'text/javascript' }));
|
|
try { await session.start(await import(/* @vite-ignore */ url)); } finally { URL.revokeObjectURL(url); }
|
|
await session.mount('settings', document.querySelector('#plugin') as HTMLElement);
|
|
return session;
|
|
},
|
|
destroy() { stopProvider(); writer.destroy(); source.destroy(); },
|
|
} });
|