Add search autocomplete (#53)

* Implement search autocomplete for recent searches

* Implement search autocomplete for bookmarks

* Fix URL encoding of query param

* Add tag suggestions to search autocomplete

Co-authored-by: Sascha Ißbrücker <sissbruecker@lyska.io>
This commit is contained in:
Sascha Ißbrücker
2020-12-31 09:47:51 +01:00
committed by GitHub
parent 816a887d99
commit c13b27e170
13 changed files with 436 additions and 28 deletions

View File

@@ -1,4 +1,6 @@
<script>
import {getCurrentWord, getCurrentWordBounds} from "./util";
export let id;
export let name;
export let value;
@@ -23,7 +25,7 @@
function handleInput(e) {
input = e.target;
const word = getCurrentWord();
const word = getCurrentWord(input);
suggestions = word ? tags.filter(tag => tag.indexOf(word) === 0) : [];
@@ -73,27 +75,6 @@
close();
}
function getCurrentWordBounds() {
const text = input.value;
const end = input.selectionStart;
let start = end;
let currentChar = text.charAt(start - 1);
while (currentChar && currentChar !== ' ' && start > 0) {
start--;
currentChar = text.charAt(start - 1);
}
return {start, end};
}
function getCurrentWord() {
const bounds = getCurrentWordBounds(input);
return input.value.substring(bounds.start, bounds.end);
}
function updateSelection(dir) {
const length = suggestions.length;