From 2539950ad7c9fd674ff7b8eb2bdad429e08d70bb Mon Sep 17 00:00:00 2001 From: Dotta Date: Mon, 16 Mar 2026 16:50:18 -0500 Subject: [PATCH] fix: add two newlines after image drop/paste in markdown editor When dragging or pasting an image into a markdown editor field, the cursor would end up right next to the image making it hard to continue typing. Now inserts two newlines after the image so a new paragraph is ready. Co-Authored-By: Paperclip --- ui/src/components/MarkdownEditor.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ui/src/components/MarkdownEditor.tsx b/ui/src/components/MarkdownEditor.tsx index 372b8a4d..a2e49d0a 100644 --- a/ui/src/components/MarkdownEditor.tsx +++ b/ui/src/components/MarkdownEditor.tsx @@ -251,6 +251,23 @@ export const MarkdownEditor = forwardRef try { const src = await handler(file); setUploadError(null); + // After MDXEditor inserts the image, ensure two newlines follow it + // so the cursor isn't stuck right next to the image. + setTimeout(() => { + const current = latestValueRef.current; + const updated = current.replace( + /!\[([^\]]*)\]\(([^)]+)\)(?!\n\n)/g, + "![$1]($2)\n\n", + ); + if (updated !== current) { + latestValueRef.current = updated; + ref.current?.setMarkdown(updated); + onChange(updated); + requestAnimationFrame(() => { + ref.current?.focus(undefined, { defaultSelection: "rootEnd" }); + }); + } + }, 100); return src; } catch (err) { const message = err instanceof Error ? err.message : "Image upload failed";