From: Jakobus Schürz Date: Tue, 14 Jan 2025 04:49:48 +0000 (+0100) Subject: do not change cursor position while replacing upload-placeholder X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c47323e358b9841eb287c71e54ae549ea5f6d62d;p=friendica.git do not change cursor position while replacing upload-placeholder fixes #14695 Save caret position just before replacing the upload-placeholder. replace upload-placeholder Set caret position to the position in textarea as before replacing action. Setting caret position considers the position before or after placeholder and therefore the textlength of server-response to find the right place. --- diff --git a/view/js/dropzone-factory.js b/view/js/dropzone-factory.js index dcc0468cb2..5c97394721 100644 --- a/view/js/dropzone-factory.js +++ b/view/js/dropzone-factory.js @@ -35,7 +35,13 @@ var DzFactory = function (max_imagesize) { if (targetTextarea.setRangeText) { //if setRangeText function is supported by current browser let u = "[upload-" + file.name + "]"; - targetTextarea.setRangeText(serverResponse, targetTextarea.value.indexOf(u), targetTextarea.value.indexOf(u) + u.length, "end"); + let c = targetTextarea.selectionStart; + if (c > targetTextarea.value.indexOf(u)) { + c = c + serverResponse.length - u.length; + } + targetTextarea.setRangeText(serverResponse, targetTextarea.value.indexOf(u), targetTextarea.value.indexOf(u) + u.length); + targetTextarea.selectionStart = c; + targetTextarea.selectionEnd = c; } else { targetTextarea.focus(); document.execCommand('insertText', false /*no UI*/, serverResponse);