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
1.9 KiB
TypeScript
32 lines
1.9 KiB
TypeScript
import type { Extension } from "@codemirror/state";
|
|
import { StreamLanguage } from "@codemirror/language";
|
|
import { markdown, markdownLanguage } from "@codemirror/lang-markdown";
|
|
import { extensionOf } from "../workspace/chrome";
|
|
import { languageFor } from "./languageFor";
|
|
import { noteFormats } from "./noteFormats";
|
|
|
|
/** The Markdown language of Write and Source, with the RuneStone note formats. */
|
|
export const noteMarkdown = () => markdown({ base: markdownLanguage, extensions: [noteFormats] });
|
|
|
|
// Each language loads when the first file of that language opens.
|
|
const loaders: Record<string, (extension: string) => Promise<Extension>> = {
|
|
markdown: async () => noteMarkdown(),
|
|
javascript: async extension => (await import("@codemirror/lang-javascript")).javascript({ jsx: extension === "jsx" }),
|
|
typescript: async extension => (await import("@codemirror/lang-javascript")).javascript({ typescript: true, jsx: extension === "tsx" }),
|
|
python: async () => (await import("@codemirror/lang-python")).python(),
|
|
json: async () => (await import("@codemirror/lang-json")).json(),
|
|
css: async () => (await import("@codemirror/lang-css")).css(),
|
|
scss: async () => (await import("@codemirror/lang-sass")).sass(),
|
|
html: async () => (await import("@codemirror/lang-html")).html(),
|
|
rust: async () => (await import("@codemirror/lang-rust")).rust(),
|
|
shell: async () => StreamLanguage.define((await import("@codemirror/legacy-modes/mode/shell")).shell),
|
|
yaml: async () => (await import("@codemirror/lang-yaml")).yaml(),
|
|
ini: async () => StreamLanguage.define((await import("@codemirror/legacy-modes/mode/toml")).toml),
|
|
xml: async () => (await import("@codemirror/lang-xml")).xml(),
|
|
};
|
|
|
|
/** The syntax support for a file. Plain text gets none. */
|
|
export async function languageSupport(relPath: string): Promise<Extension> {
|
|
return await loaders[languageFor(relPath)]?.(extensionOf(relPath)) ?? [];
|
|
}
|