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.
This commit is contained in:
Nicolas Martin 2020-10-28 01:48:07 +01:00 committed by Christian Rocha
parent 56847c1b01
commit c91501655f

View file

@ -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