diff --git a/frontend/app.js b/frontend/app.js
index 8ff8729..7f9525b 100644
--- a/frontend/app.js
+++ b/frontend/app.js
@@ -16,6 +16,7 @@
let editorView = null;
let editorVault = null;
let editorPath = null;
+ let fallbackEditorEl = null;
// ---------------------------------------------------------------------------
// File extension → Lucide icon mapping
@@ -846,41 +847,48 @@
editorView.destroy();
editorView = null;
}
+ fallbackEditorEl = null;
- // Wait for CodeMirror to be available
- await waitForCodeMirror();
+ try {
+ await waitForCodeMirror();
- const { EditorView, EditorState, basicSetup, markdown, oneDark, keymap } = window.CodeMirror;
+ const { EditorView, EditorState, basicSetup, markdown, oneDark, keymap } = window.CodeMirror;
- // Determine theme
- const currentTheme = document.documentElement.getAttribute("data-theme");
- const extensions = [
- basicSetup,
- markdown(),
- keymap.of([{
- key: "Mod-s",
- run: () => {
- saveFile();
- return true;
- }
- }]),
- EditorView.lineWrapping,
- ];
+ const currentTheme = document.documentElement.getAttribute("data-theme");
+ const extensions = [
+ basicSetup,
+ markdown(),
+ keymap.of([{
+ key: "Mod-s",
+ run: () => {
+ saveFile();
+ return true;
+ }
+ }]),
+ EditorView.lineWrapping,
+ ];
- if (currentTheme === "dark") {
- extensions.push(oneDark);
+ if (currentTheme === "dark") {
+ extensions.push(oneDark);
+ }
+
+ const state = EditorState.create({
+ doc: rawData.raw,
+ extensions: extensions,
+ });
+
+ editorView = new EditorView({
+ state: state,
+ parent: bodyEl,
+ });
+ } catch (err) {
+ console.error("CodeMirror init failed, falling back to textarea:", err);
+ fallbackEditorEl = document.createElement("textarea");
+ fallbackEditorEl.className = "fallback-editor";
+ fallbackEditorEl.value = rawData.raw;
+ bodyEl.appendChild(fallbackEditorEl);
}
- const state = EditorState.create({
- doc: rawData.raw,
- extensions: extensions,
- });
-
- editorView = new EditorView({
- state: state,
- parent: bodyEl,
- });
-
modal.classList.add("active");
safeCreateIcons();
}
@@ -903,14 +911,15 @@
editorView.destroy();
editorView = null;
}
+ fallbackEditorEl = null;
editorVault = null;
editorPath = null;
}
async function saveFile() {
- if (!editorView || !editorVault || !editorPath) return;
+ if ((!editorView && !fallbackEditorEl) || !editorVault || !editorPath) return;
- const content = editorView.state.doc.toString();
+ const content = editorView ? editorView.state.doc.toString() : fallbackEditorEl.value;
const saveBtn = document.getElementById("editor-save");
const originalText = saveBtn.textContent;
diff --git a/frontend/index.html b/frontend/index.html
index cc678bc..3a18485 100644
--- a/frontend/index.html
+++ b/frontend/index.html
@@ -9,17 +9,24 @@
+