Fix browser page scrolling by initializing EntryHeight and correcting scroll handler type assertion

This commit is contained in:
gmp
2026-06-01 10:57:34 -04:00
parent 281298ac1f
commit 6709f52e0f
17 changed files with 855 additions and 155 deletions
+10 -14
View File
@@ -85,7 +85,8 @@ const (
type BrowserState struct {
// Navigation
CurrentPath string // Currently browsed directory (relative to root)
ScrollIndex int // Index of first visible entry (not pixel offset)
ScrollOffset float64 // Vertical scroll offset in pixels
EntryHeight float64 // Height of a single entry in pixels
VisibleCount int // Number of entries currently visible
// Lazy loading
@@ -455,25 +456,20 @@ func HandleBrowserScroll(data any) {
defer state.Unlock()
scrollData := data.(ScrollEvent)
delta := int(scrollData.Delta / state.Browser.EntryHeight)
oldScrollIndex := state.Browser.ScrollIndex
state.Browser.ScrollIndex += delta
state.Browser.ScrollOffset += scrollData.Delta
// Clamp
maxScroll := state.Browser.TotalEntries - state.Browser.VisibleCount
if state.Browser.ScrollIndex < 0 {
state.Browser.ScrollIndex = 0
maxScroll := float64(state.Browser.TotalEntries)*state.Browser.EntryHeight - viewHeight
if state.Browser.ScrollOffset < 0 {
state.Browser.ScrollOffset = 0
}
if state.Browser.ScrollIndex > maxScroll {
state.Browser.ScrollIndex = maxScroll
if state.Browser.ScrollOffset > maxScroll {
state.Browser.ScrollOffset = maxScroll
}
// Trigger prefetch for newly visible pages
if state.Browser.ScrollIndex != oldScrollIndex {
dispatchPrefetchPages(state.Browser)
state.Browser.EvictPages()
}
dispatchPrefetchPages(state.Browser)
state.Browser.EvictPages()
}
```