From 58df854466cf809a53bdd72bad416104a2383a89 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Wed, 16 Dec 2020 17:55:57 -0500 Subject: [PATCH] When clearing the filter forget which markdowns were stashed in-session --- ui/stash.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/ui/stash.go b/ui/stash.go index 7762faa..8737bf7 100644 --- a/ui/stash.go +++ b/ui/stash.go @@ -249,11 +249,27 @@ func (m *stashModel) setSize(width, height int) { m.updatePagination() } +// bakeConvertedDocs turns converted documents into stashed ones. Essentially, +// we're discarding the fact that they were ever converted so we can stop +// treating them like converted documents. +func (m *stashModel) bakeConvertedDocs() { + for _, md := range m.markdowns { + if md.docType == ConvertedDoc { + md.docType = StashedDoc + } + } +} + func (m *stashModel) resetFiltering() { m.filterState = unfiltered m.filterInput.Reset() - sort.Stable(markdownsByLocalFirst(m.markdowns)) m.filteredMarkdowns = nil + + // Turn converted markdowns into stashed ones so that the next time we + // filter we get both local and stashed results. + m.bakeConvertedDocs() + + sort.Stable(markdownsByLocalFirst(m.markdowns)) m.updatePagination() if m.sections[len(m.sections)-1].key == filterSection { @@ -759,6 +775,7 @@ func (m *stashModel) handleDocumentBrowsing(msg tea.Msg) tea.Cmd { // Filter your notes case "/": m.hideStatusMessage() + m.bakeConvertedDocs() // Build values we'll filter against for _, md := range m.markdowns {