Fix insert

This commit is contained in:
pythongosssss
2023-08-28 10:47:18 +01:00
parent 3120ce89f5
commit edf4eef96a
+5 -8
View File
@@ -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);