]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/static/js/editor.js
wiki: Use setRangeText and move cursor to end when replacing text
[ipfire.org.git] / 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) {