]> git.mxchange.org Git - friendica.git/commitdiff
do not change cursor position while replacing upload-placeholder
authorJakobus Schürz <jakobus.schuerz@home.arpa>
Tue, 14 Jan 2025 04:49:48 +0000 (05:49 +0100)
committerJakobus Schürz <jakobus.schuerz@home.arpa>
Tue, 14 Jan 2025 04:49:48 +0000 (05:49 +0100)
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.

view/js/dropzone-factory.js

index dcc0468cb2f6db1617a5ef7d3005c2ad6c68eefc..5c973947210a100e59efb260c8c154a377e57909 100644 (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);