diff --git a/src/lib/components/chat/ModelSelector/Selector.svelte b/src/lib/components/chat/ModelSelector/Selector.svelte index 4c442568fe..dce53f6408 100644 --- a/src/lib/components/chat/ModelSelector/Selector.svelte +++ b/src/lib/components/chat/ModelSelector/Selector.svelte @@ -361,6 +361,18 @@ ); } }; + + const ITEM_HEIGHT = 42; + const OVERSCAN = 10; + + let listScrollTop = 0; + let listContainer; + + $: visibleStart = Math.max(0, Math.floor(listScrollTop / ITEM_HEIGHT) - OVERSCAN); + $: visibleEnd = Math.min( + filteredItems.length, + Math.ceil((listScrollTop + 256) / ITEM_HEIGHT) + OVERSCAN + ); -
- {#each filteredItems as item, index} - { - value = item.value; - selectedModelIdx = index; - - show = false; - }} - /> - {:else} +
+ {#if filteredItems.length === 0}
{$i18n.t('No results found')}
- {/each} + {:else} + +
{ + listScrollTop = listContainer.scrollTop; + }} + > +
+ {#each filteredItems.slice(visibleStart, visibleEnd) as item, i (item.value)} + {@const index = visibleStart + i} + { + value = item.value; + selectedModelIdx = index; + + show = false; + }} + /> + {/each} +
+
+ {/if} {#if !(searchValue.trim() in $MODEL_DOWNLOAD_POOL) && searchValue && ollamaVersion && $user?.role === 'admin'}