From e341d666afe19875552f6c4bcfb537c8b6c7488c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20I=C3=9Fbr=C3=BCcker?= Date: Fri, 27 Dec 2019 12:46:54 +0100 Subject: [PATCH] Implement tag auto-completion --- bookmarks/components/TagAutocomplete.svelte | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/bookmarks/components/TagAutocomplete.svelte b/bookmarks/components/TagAutocomplete.svelte index a3676cb..0616ebd 100644 --- a/bookmarks/components/TagAutocomplete.svelte +++ b/bookmarks/components/TagAutocomplete.svelte @@ -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;