fix(electrobun): remove read+write cycle in CommandPalette clamp selection
This commit is contained in:
parent
b2b1e429dc
commit
774016ba11
1 changed files with 4 additions and 3 deletions
|
|
@ -88,11 +88,11 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Clamp selection when filtered list changes
|
// Clamp selection when query changes (NOT via $effect — avoids read+write cycle)
|
||||||
$effect(() => {
|
function clampSelection() {
|
||||||
const len = filtered.length;
|
const len = filtered.length;
|
||||||
if (selectedIdx >= len) selectedIdx = Math.max(0, len - 1);
|
if (selectedIdx >= len) selectedIdx = Math.max(0, len - 1);
|
||||||
});
|
}
|
||||||
|
|
||||||
function handleKeydown(e: KeyboardEvent) {
|
function handleKeydown(e: KeyboardEvent) {
|
||||||
if (e.key === 'Escape') { onClose(); return; }
|
if (e.key === 'Escape') { onClose(); return; }
|
||||||
|
|
@ -138,6 +138,7 @@
|
||||||
placeholder={t('palette.placeholder')}
|
placeholder={t('palette.placeholder')}
|
||||||
bind:this={inputEl}
|
bind:this={inputEl}
|
||||||
bind:value={query}
|
bind:value={query}
|
||||||
|
oninput={() => clampSelection()}
|
||||||
onkeydown={handleKeydown}
|
onkeydown={handleKeydown}
|
||||||
aria-label="Command search"
|
aria-label="Command search"
|
||||||
aria-autocomplete="list"
|
aria-autocomplete="list"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue