From 39531d875e9d7c31e1e47a622025576a47191a10 Mon Sep 17 00:00:00 2001 From: sk-ys Date: Sat, 10 Jan 2026 17:49:37 +0900 Subject: [PATCH] Fix cursor position handling after inserting inline attachment markup --- app/assets/javascripts/attachments.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/attachments.js b/app/assets/javascripts/attachments.js index 0d823a63f..4eead282d 100644 --- a/app/assets/javascripts/attachments.js +++ b/app/assets/javascripts/attachments.js @@ -313,14 +313,14 @@ function addInlineAttachmentMarkup(file) { + (newLineAfter ? '\n' : '') + description.substring(cursorPosition, description.length) ); - }) - - // move cursor into next line - cursorPosition = $textarea.prop('selectionStart'); - $textarea.prop({ - 'selectionStart': cursorPosition + 1, - 'selectionEnd': cursorPosition + 1 - }); + + // Move cursor after the inserted markup + var newCursorPosition = cursorPosition + (newLineBefore ? 1 : 0) + imageMarkup.length; + $textarea.prop({ + 'selectionStart': newCursorPosition + 1, + 'selectionEnd': newCursorPosition + 1 + }); + }); } } -- 2.45.1.windows.1