Implement tag auto-completion

This commit is contained in:
Sascha Ißbrücker 2019-12-27 12:46:54 +01:00
parent 70b66122c8
commit e341d666af
1 changed files with 8 additions and 11 deletions

View File

@ -22,14 +22,16 @@
function handleInput(e) {
input = e.target;
const word = getCurrentWord(e.target);
if (!word) {
const word = getCurrentWord();
suggestions = word ? tags.filter(tag => tag.indexOf(word) === 0) : [];
if (word && suggestions.length > 0) {
open();
} else {
close();
return;
}
open(word);
}
function handleKeyDown(e) {
@ -52,9 +54,8 @@
}
}
function open(word) {
function open() {
isOpen = true;
updateSuggestions(word);
selectedIndex = 0;
}
@ -93,10 +94,6 @@
return input.value.substring(bounds.start, bounds.end);
}
function updateSuggestions(word) {
suggestions = tags.filter(tag => tag.indexOf(word) === 0);
}
function updateSelection(dir) {
const length = suggestions.length;