Fix pasted images disappearing when switching to source mode (#87)

This commit is contained in:
Yuri Karamian
2026-06-19 11:30:07 +02:00
parent 83390f5ed2
commit c1a9871703
+11 -11
View File
@@ -4634,24 +4634,24 @@
} }
} else if (!isSource && lastSourceMode) { } else if (!isSource && lastSourceMode) {
lastSourceMode = false; lastSourceMode = false;
if (isMobile) {
// Mobile: editor stays in DOM, just update its content
const content = sourceContent || ($activeNote?.content ?? ''); const content = sourceContent || ($activeNote?.content ?? '');
// Wait for Svelte to toggle display back to the editor element,
// then update content. The editor stays alive (no destroy/recreate).
tick().then(() => {
if (editor) { if (editor) {
ignoreNextUpdate = true; ignoreNextUpdate = true;
editor.commands.setContent(markdownToHtml(content)); editor.commands.setContent(markdownToHtml(content));
// Force image re-render for WebViews that don't trigger loads on setContent }
requestAnimationFrame(() => { } else {
if (!editor) return; // Desktop: destroy old editor, wait for DOM swap, then recreate.
editor.view.dom.querySelectorAll('img').forEach((img) => { destroyEditor();
const src = img.getAttribute('src'); const content = sourceContent || ($activeNote?.content ?? '');
if (src) img.setAttribute('src', src); 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)