fix(electrobun): remove read+write cycle in CommandPalette clamp selection

This commit is contained in:
Hibryda 2026-03-24 12:54:58 +01:00
parent b2b1e429dc
commit 774016ba11

View file

@ -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"