Fix browser page scrolling by initializing EntryHeight and correcting scroll handler type assertion
This commit is contained in:
@@ -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()
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user