From aba133b7e64cc60abfd1677b1ff4810beb17bae9 Mon Sep 17 00:00:00 2001 From: Nicolas Martin Date: Wed, 28 Oct 2020 02:17:18 +0100 Subject: [PATCH] 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()`. --- ui/stash.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ui/stash.go b/ui/stash.go index eadce02..46c072e 100644 --- a/ui/stash.go +++ b/ui/stash.go @@ -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 {