From 6eb53879591bd0b1573da7ce7d001523a1b25ff2 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 27 Aug 2019 14:22:39 +0100 Subject: [PATCH] wiki: Use setRangeText and move cursor to end when replacing text Signed-off-by: Michael Tremer --- src/static/js/editor.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/static/js/editor.js b/src/static/js/editor.js index 7639ae2e..39fac6b2 100644 --- a/src/static/js/editor.js +++ b/src/static/js/editor.js @@ -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) { -- 2.39.2