From c1a9871703f90cc7719b6bdfa704bfbe2a8951ff Mon Sep 17 00:00:00 2001 From: Yuri Karamian Date: Fri, 19 Jun 2026 11:30:07 +0200 Subject: [PATCH] Fix pasted images disappearing when switching to source mode (#87) --- src/lib/components/Editor.svelte | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/lib/components/Editor.svelte b/src/lib/components/Editor.svelte index fc4c908..5fbebb5 100644 --- a/src/lib/components/Editor.svelte +++ b/src/lib/components/Editor.svelte @@ -4634,23 +4634,23 @@ } } else if (!isSource && lastSourceMode) { lastSourceMode = false; - 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 (isMobile) { + // Mobile: editor stays in DOM, just update its content + const content = sourceContent || ($activeNote?.content ?? ''); if (editor) { ignoreNextUpdate = true; editor.commands.setContent(markdownToHtml(content)); - // Force image re-render for WebViews that don't trigger loads on setContent - requestAnimationFrame(() => { - if (!editor) return; - editor.view.dom.querySelectorAll('img').forEach((img) => { - const src = img.getAttribute('src'); - if (src) img.setAttribute('src', src); - }); - }); } - }); + } else { + // Desktop: destroy old editor, wait for DOM swap, then recreate. + destroyEditor(); + const content = sourceContent || ($activeNote?.content ?? ''); + tick().then(() => { + if (editorElement && !editor) { + createEditor(content); + } + }); + } } });