Replace split textarea/preview editor with a single CodeMirror Markdown editor

This commit is contained in:
avi 2026-08-17 11:15:23 -05:00
commit 1ae9744b2b
7 changed files with 451 additions and 200 deletions

View file

@ -82,6 +82,33 @@ const BOOK_DIR = __BOOKDIR_VALUE__;
out.uiCreated = metaAfterUi.chapterOrder.length === countBefore + 1 &&
Object.values(metaAfterUi.chapters).some((c) => c.title === "Via Modal");
// CodeMirror editor: typing, cursor/selection, autosave persistence
const cm = window.__folioEditor;
out.hasEditor = !!cm;
out.editorLoaded = cm ? cm.state.doc.toString() : null;
if (cm) {
cm.dispatch({
changes: {
from: 0,
to: cm.state.doc.length,
insert: "# Heading One\n\n**bold** and *italic* text\n\n- bullet one\n- bullet two\n\n> quoted line\n\n[link](https://example.com) and `inline code`\n\n---",
},
});
cm.dispatch({ selection: { anchor: cm.state.doc.length } });
}
await new Promise((r) => setTimeout(r, 1200));
out.editorDocAfterType = cm ? cm.state.doc.toString() : null;
const typedId = metaAfterUi.chapterOrder[metaAfterUi.chapterOrder.length - 1];
const typedContent = await window.folio.getChapterContent(typedId);
out.editorAutosaved =
!!cm &&
cm.state.doc.toString().includes("**bold** and *italic*") &&
typedContent.includes("# Heading One") &&
typedContent.includes("- bullet two") &&
typedContent.includes("> quoted line") &&
typedContent.includes("[link](https://example.com)") &&
typedContent.includes("`inline code`");
out.all = true;
} catch (e) {
out.error = String((e && e.message) || e);