char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
bdffafa5d
char/aliceai-t5-moe
1import { untrack } from 'svelte' ; 2 3/** 4* Scrolls the highlighted row of a picker list into view when the scroll 5* trigger is bumped, without scrolling on mouse hover or result 6* replacement. 7*/ 8export interface UseScrollActiveRowOptions { 9/** Counter bumped by keyboard nav; `undefined` disables the effect. */ 10getTrigger :() => number | undefined ; 11getContainer :() => HTMLDivElement | null ; 12getIndex :() => number ; 13getCount :() => number ; 14/** Full data attribute marking the row, e.g. `data-picker-index`. */ 15dataAttr :string ; 16} 17 18export function useScrollActiveRow ( opts :UseScrollActiveRowOptions ) { 19let lastTrigger :number | null = null ; 20 21$effect (() => { 22const trigger = opts . getTrigger (); 23 24if ( trigger === undefined ) return ; 25 26// Skip the initial run on mount: the list opens with the first row 27// already in view, and scrolling here fires before the popover is 28// positioned, which would scroll the whole page to the top. 29if ( lastTrigger === null ) { 30lastTrigger = trigger ; 31 32return ; 33} 34 35if ( trigger === lastTrigger ) return ; 36 37lastTrigger = trigger ; 38untrack (() => { 39const container = opts . getContainer (); 40const index = opts . getIndex (); 41 42if ( ! container || index < 0 || index >= opts . getCount ()) return ; 43 44const row = container . querySelector ( `[ ${ opts . dataAttr } =" ${ index } "]` ) as HTMLElement | null ; 45 46row ?. scrollIntoView ({ block :'nearest' , inline :'nearest' }); 47}); 48}); 49} 50 51export type UseScrollActiveRowReturn = ReturnType < typeof useScrollActiveRow >;