From edf4eef96a190155af7da14b4d1c2380eccf41e3 Mon Sep 17 00:00:00 2001 From: pythongosssss <125205205+pythongosssss@users.noreply.github.com> Date: Mon, 28 Aug 2023 10:47:18 +0100 Subject: [PATCH] Fix insert --- web/js/common/autocomplete.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/web/js/common/autocomplete.js b/web/js/common/autocomplete.js index 211c42f..b0f4daa 100644 --- a/web/js/common/autocomplete.js +++ b/web/js/common/autocomplete.js @@ -284,16 +284,13 @@ class TextAreaCaretHelper { return this.el.value.substring(this.el.selectionEnd); } - insertAtCursor(value) { - if (document.selection) { - this.el.focus(); - sel = document.selection.createRange(); - sel.text = value; - } else if (this.el.selectionStart) { + insertAtCursor(value, offset) { + if (this.el.selectionStart != null) { const startPos = this.el.selectionStart; const endPos = this.el.selectionEnd; + this.el.value = - this.el.value.substring(0, startPos) + value + this.el.value.substring(endPos, this.el.value.length); + this.el.value.substring(0, startPos + offset) + value + this.el.value.substring(endPos, this.el.value.length); this.el.selectionStart = startPos + value.length; this.el.selectionEnd = startPos + value.length; } else { @@ -518,7 +515,7 @@ export class TextAreaAutoComplete { { onclick: () => { this.el.focus(); - this.helper.insertAtCursor(wordInfo.text.substr(before.length)); + this.helper.insertAtCursor(wordInfo.text, -before.length); setTimeout(() => { this.#update(); }, 150);