]> git.ipfire.org Git - ipfire.org.git/commitdiff
wiki: Use setRangeText and move cursor to end when replacing text
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 27 Aug 2019 13:22:39 +0000 (14:22 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 27 Aug 2019 14:22:54 +0000 (15:22 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/static/js/editor.js

index 7639ae2eaa09bd13f436f6b17967cf0cd9f1e453..39fac6b214c0b91e4986cf6da60c4c0d3289c245 100644 (file)
@@ -45,12 +45,12 @@ class Editor {
     // Functions to modify the text
 
     replaceSelection(replacement) {
-        var text = this.textarea.val();
+        // Get the DOM element
+        var textarea = this.textarea.get(0);
 
-        text = text.slice(0, this.selection.start) + replacement + text.slice(this.selection.end);
-
-        // Write text to textarea
-        this.textarea.val(text);
+        // Write text to textarea and move the cursor to the end
+        textarea.setRangeText(replacement,
+            this.selection.start, this.selection.end, "end");
     }
 
     insertAtCursor(insertion) {