package browser // HandleScroll updates the browser scroll index by the given delta (in entries). // Clamps to valid bounds and triggers prefetch/eviction as needed. func HandleScroll(s *BrowserState, delta int) { deltaPx := int(float64(delta) * s.EntryHeight) HandlePixelScroll(s, deltaPx) } // HandlePixelScroll updates the browser scroll offset by the given delta (in pixels). // Clamps to valid bounds and triggers eviction as needed. func HandlePixelScroll(s *BrowserState, delta int) { s.ScrollOffset += float64(delta) // Clamp to valid bounds clampScrollOffset(s) // Trigger eviction of distant pages s.EvictPages() } // clampScrollOffset ensures the scroll offset stays within valid bounds. func clampScrollOffset(s *BrowserState) { if s.ScrollOffset < 0 { s.ScrollOffset = 0 } // If there's no scrollable area (entries fit in viewport), clamp to 0 if s.TotalEntries <= s.VisibleCount { s.ScrollOffset = 0 return } maxScroll := float64(s.TotalEntries-s.VisibleCount) * s.EntryHeight if s.ScrollOffset > maxScroll { s.ScrollOffset = maxScroll } }