There's always at least 1 page available in the paginator

Passing 0 to `paginator.SetTotalPages()` is ineffective as it won't alter the
model (paginator needs at least 1 page) and therefore doesn't update the page
count. Filtering can lead to 0 items in the stash view - in this case we still
want to have a page available in the paginator - so we also have pass 1 to
`setTotalPages()`.
This commit is contained in:
Nicolas Martin 2020-10-28 02:17:18 +01:00 committed by Christian Rocha
commit aba133b7e6

View file

@ -133,10 +133,13 @@ func (m *stashModel) setSize(width, height int) {
// Sets the total paginator pages according to the amount of markdowns for the
// current state.
func (m *stashModel) setTotalPages() {
pages := len(m.getNotes())
m.paginator.PerPage = max(1, (m.terminalHeight-stashViewTopPadding-stashViewBottomPadding)/stashViewItemHeight)
m.paginator.SetTotalPages(pages)
if pages := len(m.getNotes()); pages < 1 {
m.paginator.SetTotalPages(1)
} else {
m.paginator.SetTotalPages(pages)
}
// Make sure the page stays in bounds
if m.paginator.Page >= m.paginator.TotalPages-1 {