Skip to content

The open-source app everyone uses to manage agents at work

fix: add two newlines after image drop/paste in markdown editor

Dotta2539950ad7c9
diff --git a/ui/src/components/MarkdownEditor.tsx b/ui/src/components/MarkdownEditor.tsx
index 372b8a4dbf..a2e49d0a95 100644
--- a/ui/src/components/MarkdownEditor.tsx
+++ b/ui/src/components/MarkdownEditor.tsx
@@ -251,6 +251,23 @@ export const MarkdownEditor = forwardRef<MarkdownEditorRef, MarkdownEditorProps>
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";