diff options
author | Christian Rocha <christian@rocha.is> | 2020-07-15 16:03:05 -0400 |
---|---|---|
committer | Christian Muehlhaeuser <muesli@gmail.com> | 2020-10-05 13:50:04 +0200 |
commit | df95fa6ba9f85512f97396401ee4ad05c866c113 (patch) | |
tree | 6c90174cc82500521a80f34fdee2de9890ce3e81 /ui | |
parent | 1bf2298536365aa6611b12cf0ce2ede6b9cd7e20 (diff) |
Selection index in file shouldn't dip below 0
Diffstat (limited to 'ui')
-rw-r--r-- | ui/stash.go | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/ui/stash.go b/ui/stash.go index 35c89c3..ba817f0 100644 --- a/ui/stash.go +++ b/ui/stash.go @@ -146,16 +146,18 @@ func (m stashModel) selectedMarkdown() *markdown { // addDocuments adds markdown documents to the model func (m *stashModel) addMarkdowns(mds ...*markdown) { - m.markdowns = append(m.markdowns, mds...) - sort.Sort(markdownsByLocalFirst(m.markdowns)) - m.paginator.SetTotalPages(len(m.markdowns)) + if len(mds) > 0 { + m.markdowns = append(m.markdowns, mds...) + sort.Sort(markdownsByLocalFirst(m.markdowns)) + m.paginator.SetTotalPages(len(m.markdowns)) + } } // INIT func newStashModel() stashModel { s := spinner.NewModel() - s.Frames = spinner.Dot + s.Frames = spinner.Line s.ForegroundColor = common.SpinnerColor p := paginator.NewModel() @@ -313,7 +315,7 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) { // Keep the index in bounds when paginating itemsOnPage := m.paginator.ItemsOnPage(len(m.markdowns)) if m.index > itemsOnPage-1 { - m.index = itemsOnPage - 1 + m.index = max(0, itemsOnPage-1) } // If we're on the last page and we haven't loaded everything, get |