feat(list): infinite scrolling (#316)

This commit is contained in:
jon4hz
2023-03-24 11:05:53 -07:00
committed by GitHub
parent 876d5af152
commit 5b22c92cf3
+16 -2
View File
@@ -132,8 +132,9 @@ type Model struct {
itemNameSingular string
itemNamePlural string
Title string
Styles Styles
Title string
Styles Styles
InfiniteScrolling bool
// Key mappings for navigating the list.
KeyMap KeyMap
@@ -459,6 +460,13 @@ func (m *Model) CursorUp() {
// If we're at the start, stop
if m.cursor < 0 && m.Paginator.Page == 0 {
// if infinite scrolling is enabled, go to the last item
if m.InfiniteScrolling {
m.Paginator.Page = m.Paginator.TotalPages - 1
m.cursor = m.Paginator.ItemsOnPage(len(m.VisibleItems())) - 1
return
}
m.cursor = 0
return
}
@@ -501,6 +509,12 @@ func (m *Model) CursorDown() {
}
m.cursor = itemsOnPage - 1
// if infinite scrolling is enabled, go to the first item
if m.InfiniteScrolling {
m.Paginator.Page = 0
m.cursor = 0
}
}
// PrevPage moves to the previous page, if available.