improved autocomplete
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -15,7 +15,8 @@
|
|||||||
const ignore = ['ArrowLeft','ArrowRight'];
|
const ignore = ['ArrowLeft','ArrowRight'];
|
||||||
//let candidate = $state({ display : '' });
|
//let candidate = $state({ display : '' });
|
||||||
let selected = $state([]);
|
let selected = $state([]);
|
||||||
let candidates = $derived(getCandidates(candidate.display));
|
let candidates = $state([]);
|
||||||
|
let timer = null;
|
||||||
|
|
||||||
async function dummyGetCandidates(text){
|
async function dummyGetCandidates(text){
|
||||||
console.warn(`getCandidates(${text}) not overridden!`);
|
console.warn(`getCandidates(${text}) not overridden!`);
|
||||||
@@ -56,6 +57,11 @@
|
|||||||
onSelect(candidate);
|
onSelect(candidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchCandidates(){
|
||||||
|
candidates = await getCandidates(candidate.display);
|
||||||
|
if (selected>candidates.length) selected = candidates.length;
|
||||||
|
}
|
||||||
|
|
||||||
async function onkeyup(ev){
|
async function onkeyup(ev){
|
||||||
if (ignore.includes(ev.key)) return;
|
if (ignore.includes(ev.key)) return;
|
||||||
if (ev.key == 'ArrowDown'){
|
if (ev.key == 'ArrowDown'){
|
||||||
@@ -94,8 +100,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
candidate = { display : candidate.display };
|
candidate = { display : candidate.display };
|
||||||
candidates = await getCandidates(candidate.display);
|
if (timer) clearTimeout(timer);
|
||||||
if (selected>candidates.length) selected = candidates.length;
|
timer = setTimeout(fetchCandidates,400);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -109,7 +115,7 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<span>
|
<span>
|
||||||
<input type="text" bind:value={candidate.display} {onkeyup} autofocus={autofocus} {id} />
|
<input type="text" bind:value={candidate.display} {onkeyup} autofocus={autofocus} />
|
||||||
{#if candidates && candidates.length > 0}
|
{#if candidates && candidates.length > 0}
|
||||||
<select bind:value={selected} {ondblclick} multiple tabindex="-1">
|
<select bind:value={selected} {ondblclick} multiple tabindex="-1">
|
||||||
{#each candidates as candidate,i}
|
{#each candidates as candidate,i}
|
||||||
|
|||||||
Reference in New Issue
Block a user