diff --git a/frontend/src/Components/Autocomplete.svelte b/frontend/src/Components/Autocomplete.svelte index 37c0f8ef..ffeab064 100644 --- a/frontend/src/Components/Autocomplete.svelte +++ b/frontend/src/Components/Autocomplete.svelte @@ -15,7 +15,8 @@ const ignore = ['ArrowLeft','ArrowRight']; //let candidate = $state({ display : '' }); let selected = $state([]); - let candidates = $derived(getCandidates(candidate.display)); + let candidates = $state([]); + let timer = null; async function dummyGetCandidates(text){ console.warn(`getCandidates(${text}) not overridden!`); @@ -56,6 +57,11 @@ onSelect(candidate); } + async function fetchCandidates(){ + candidates = await getCandidates(candidate.display); + if (selected>candidates.length) selected = candidates.length; + } + async function onkeyup(ev){ if (ignore.includes(ev.key)) return; if (ev.key == 'ArrowDown'){ @@ -94,8 +100,8 @@ } candidate = { display : candidate.display }; - candidates = await getCandidates(candidate.display); - if (selected>candidates.length) selected = candidates.length; + if (timer) clearTimeout(timer); + timer = setTimeout(fetchCandidates,400); return false; } @@ -109,7 +115,7 @@ - + {#if candidates && candidates.length > 0}