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.
This commit is contained in:
Jakobus Schürz 2025-01-14 05:49:48 +01:00
parent 47946b1cb7
commit c47323e358

View file

@ -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);