diff --git a/public/js/app.js b/public/js/app.js index dd7fb19..a7cbffe 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -20,7 +20,8 @@ document.addEventListener('alpine:init', () => { }, async fetchSuggestions() { - const currentWord = getCurrentWordFromCursor(this.search, this.cursor); + const currentWord = getCurrentWordFromCursor(this.$refs.search.value, + this.cursor); if (!currentWord) return; if (currentWord === this.currentWord) { @@ -58,16 +59,14 @@ document.addEventListener('alpine:init', () => { this.items = []; this.activeItem = null; - this.search = mySplice(this.search, pos, this.currentWord.length, - tag + ' '); - this.cursor = - this.$refs.search.selectionStart = - this.$refs.search.selectionEnd = - pos + tag.length + 1; + this.$refs.search.value = mySplice(this.$refs.search.value, pos, + this.currentWord.length, tag + ' '); + this.cursor = pos + tag.length + 1; this.currentWord = ''; this.open = false; this.$refs.search.focus(); + this.$refs.search.setSelectionRange(this.cursor, this.cursor); }, autocompleteItem(evt) { diff --git a/templates/_search.html.ep b/templates/_search.html.ep index 3cd3b0f..95b70c1 100644 --- a/templates/_search.html.ep +++ b/templates/_search.html.ep @@ -9,7 +9,6 @@ @click.outside="open = false"> " placeholder="Search tags..." x-ref="search" - x-model="search" @input.debounce="fetchSuggestionsOnInput" @keydown.tab="autocompleteItem" @keydown.enter="autocompleteItem"