From c91501655ffa492aeffcfda4b9048104488bc163 Mon Sep 17 00:00:00 2001 From: Nicolas Martin Date: Wed, 28 Oct 2020 01:48:07 +0100 Subject: [PATCH] Dont panic during actions in the filtered stash view w/o items Filterng down the stash to 0 items (no cursor is displayed as there are no items left) caused a panic during execution of one of these actions: - x: Delete - m: Set Memo - s: Stash file This change prevents that from happening by breaking the switch statement when there are no items left. Also glow now uses the filtered markdown notes in the `stashHelpView` so `m.selectedMarkdown()` cannot return a nil refernce anymore. --- ui/stash.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ui/stash.go b/ui/stash.go index 218b6b2..c1311b6 100644 --- a/ui/stash.go +++ b/ui/stash.go @@ -505,6 +505,10 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) { case "m": m.hideStatusMessage() + if pages == 0 { + break + } + md := m.selectedMarkdown() isUserMarkdown := md.markdownType == stashedMarkdown || md.markdownType == convertedMarkdown isSettingNote := m.state == stashStateSettingNote @@ -523,6 +527,10 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) { break } + if pages == 0 { + break + } + md := m.selectedMarkdown() // is the file in the process of being stashed? @@ -553,6 +561,10 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) { case "x": m.hideStatusMessage() + if pages == 0 { + break + } + t := m.selectedMarkdown().markdownType isUserMarkdown := t == stashedMarkdown || t == convertedMarkdown isValidState := m.state != stashStateSettingNote @@ -933,7 +945,7 @@ func stashHelpView(m stashModel) string { isLocal bool ) - if len(m.markdowns) > 0 { + if len(m.getNotes()) > 0 { md := m.selectedMarkdown() isStashed = md != nil && md.markdownType == stashedMarkdown isLocal = md != nil && md.markdownType == localMarkdown