mirror of
https://gitlab.com/ArkHost/HelixNotes.git
synced 2026-07-24 07:45:57 +02:00
Fix editor not rendering on every other source mode switch
This commit is contained in:
@@ -4616,36 +4616,37 @@
|
|||||||
// Only act if we have a loaded note
|
// Only act if we have a loaded note
|
||||||
if (!loadedPath) return;
|
if (!loadedPath) return;
|
||||||
|
|
||||||
if (isSource && !lastSourceMode) {
|
// untrack: prevent flushSave() (inside destroyEditor) from adding
|
||||||
// Switching TO source: extract markdown from editor
|
// $editorDirty/$activeNote as effect dependencies, which causes
|
||||||
sourceContent = editor ? editorToMarkdown() : ($activeNote?.content ?? '');
|
// the effect to re-run and race with tick().then() — resulting in
|
||||||
resetSourceHistory(sourceContent);
|
// the editor failing to render on every other source-mode switch.
|
||||||
lastSourceMode = true;
|
untrack(() => {
|
||||||
} else if (!isSource && lastSourceMode) {
|
if (isSource && !lastSourceMode) {
|
||||||
lastSourceMode = false;
|
// Switching TO source: extract markdown from editor
|
||||||
if (isMobile) {
|
sourceContent = editor ? editorToMarkdown() : ($activeNote?.content ?? '');
|
||||||
// Mobile: editor stays in DOM, just update its content
|
resetSourceHistory(sourceContent);
|
||||||
const content = sourceContent || ($activeNote?.content ?? '');
|
lastSourceMode = true;
|
||||||
if (editor) {
|
} else if (!isSource && lastSourceMode) {
|
||||||
ignoreNextUpdate = true;
|
lastSourceMode = false;
|
||||||
editor.commands.setContent(markdownToHtml(content));
|
if (isMobile) {
|
||||||
}
|
// Mobile: editor stays in DOM, just update its content
|
||||||
} else {
|
const content = sourceContent || ($activeNote?.content ?? '');
|
||||||
// Desktop: destroy old editor, wait for DOM swap, then recreate.
|
if (editor) {
|
||||||
destroyEditor();
|
ignoreNextUpdate = true;
|
||||||
const content = sourceContent || ($activeNote?.content ?? '');
|
editor.commands.setContent(markdownToHtml(content));
|
||||||
tick().then(() => {
|
|
||||||
if (editorElement && !editor) {
|
|
||||||
createEditor(content);
|
|
||||||
} else if (!editor) {
|
|
||||||
// editorElement not ready yet — retry next frame
|
|
||||||
requestAnimationFrame(() => {
|
|
||||||
if (editorElement && !editor) createEditor(content);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
// Desktop: destroy old editor, wait for DOM swap, then recreate.
|
||||||
|
destroyEditor();
|
||||||
|
const content = sourceContent || ($activeNote?.content ?? '');
|
||||||
|
tick().then(() => {
|
||||||
|
if (editorElement && !editor) {
|
||||||
|
createEditor(content);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Tauri drag-drop listener for OS file drops (browser DragEvent doesn't have files in Tauri)
|
// Tauri drag-drop listener for OS file drops (browser DragEvent doesn't have files in Tauri)
|
||||||
|
|||||||
Reference in New Issue
Block a user