Fix images not rendering when switching back from source mode

This commit is contained in:
Yuri Karamian
2026-06-19 11:25:45 +02:00
parent a1913558b9
commit 5bf6d8063e
+16 -16
View File
@@ -4634,22 +4634,22 @@
} }
} else if (!isSource && lastSourceMode) { } else if (!isSource && lastSourceMode) {
lastSourceMode = false; lastSourceMode = false;
if (isMobile) { // Both desktop and mobile: keep editor alive, just update content.
// Mobile: editor stays in DOM, just update its content // Destroying/recreating the editor on desktop caused images not to
const content = sourceContent || ($activeNote?.content ?? ''); // render on the first switch back from source mode.
if (editor) { const content = sourceContent || ($activeNote?.content ?? '');
ignoreNextUpdate = true; if (editor) {
editor.commands.setContent(markdownToHtml(content)); ignoreNextUpdate = true;
} editor.commands.setContent(markdownToHtml(content));
} else { // Force a re-render of images that may not load after setContent
// Desktop: destroy old editor (its DOM element is gone), requestAnimationFrame(() => {
// wait for DOM to swap textarea→div, then create editor on new element. if (!editor) return;
destroyEditor(); editor.view.dom.querySelectorAll('img').forEach((img) => {
const content = sourceContent || ($activeNote?.content ?? ''); const src = img.getAttribute('src');
tick().then(() => { if (src) {
if (editorElement && !editor) { img.setAttribute('src', src);
createEditor(content); }
} });
}); });
} }
} }