From 8a305ec99c4e05c3c6e1c8dbba31e3b2a9b7ae8c Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Fri, 23 Jan 2026 02:47:13 +0000 Subject: [PATCH] Fix race condition in addInlineAttachmentMarkup causing cursor movement before async image markup insertion (#43662). Patch by Yasu Saku (user:skys). git-svn-id: https://svn.redmine.org/redmine/trunk@24352 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/assets/javascripts/attachments.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/attachments.js b/app/assets/javascripts/attachments.js index 0d823a63f..ef04b4315 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 + }); + }); } }