diff --git a/src/lib/components/chat/ModelSelector/Selector.svelte b/src/lib/components/chat/ModelSelector/Selector.svelte index d517db6fd..832494528 100644 --- a/src/lib/components/chat/ModelSelector/Selector.svelte +++ b/src/lib/components/chat/ModelSelector/Selector.svelte @@ -43,6 +43,8 @@ let searchValue = ''; let ollamaVersion = null; + let selectedModelIdx = 0; + $: filteredItems = items.filter( (item) => (searchValue @@ -202,6 +204,7 @@ bind:open={show} onOpenChange={async () => { searchValue = ''; + selectedModelIdx = 0; window.setTimeout(() => document.getElementById('model-search-input')?.focus(), 0); }} closeFocus={false} @@ -240,9 +243,20 @@ autocomplete="off" on:keydown={(e) => { if (e.code === 'Enter' && filteredItems.length > 0) { - value = filteredItems[0].value; + value = filteredItems[selectedModelIdx].value; show = false; + return; // dont need to scroll on selection + } else if (e.code === 'ArrowDown') { + selectedModelIdx = Math.min(selectedModelIdx + 1, filteredItems.length - 1); + } else if (e.code === 'ArrowUp') { + selectedModelIdx = Math.max(selectedModelIdx - 1, 0); + } else { + // if the user types something, reset to the top selection. + selectedModelIdx = 0; } + + const item = document.querySelector(`[data-arrow-selected="true"]`); + item?.scrollIntoView({ block: 'center', inline: 'nearest', behavior: 'instant' }); }} /> @@ -255,11 +269,13 @@