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
$effect(() => {
// Clamp selection when query changes (NOT via $effect — avoids read+write cycle)
function clampSelection() {
const len = filtered.length;
if (selectedIdx >= len) selectedIdx = Math.max(0, len - 1);
});
}
function handleKeydown(e: KeyboardEvent) {
if (e.key === 'Escape') { onClose(); return; }
@ -138,6 +138,7 @@
placeholder={t('palette.placeholder')}
bind:this={inputEl}
bind:value={query}
oninput={() => clampSelection()}
onkeydown={handleKeydown}
aria-label="Command search"
aria-autocomplete="list"