From 3a572216ade19cde289618eb16ea2435b76b0afa Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Mon, 1 Mar 2021 16:10:28 -0500 Subject: [PATCH] Update pagintion after changing sections when resetting the filter Fixes #251 --- ui/stash.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ui/stash.go b/ui/stash.go index c5e571c..927a7fb 100644 --- a/ui/stash.go +++ b/ui/stash.go @@ -313,14 +313,21 @@ func (m *stashModel) resetFiltering() { m.bakeConvertedDocs() sort.Stable(markdownsByLocalFirst(m.markdowns)) - m.updatePagination() + // If the filtered section is present (it's always at the end) slice it out + // of the sections slice to remove it from the UI. if m.sections[len(m.sections)-1].key == filterSection { m.sections = m.sections[:len(m.sections)-1] } + + // If the current section is out of bounds (it would be if we cut down the + // slice above) then return to the first section. if m.sectionIndex > len(m.sections)-1 { m.sectionIndex = 0 } + + // Update pagination after we've switched sections. + m.updatePagination() } // Is a filter currently being applied?