msgstore: check if message index < 0, select 0 if so

Calling :prev without this check can cause the index to go below 0 if
the current index is smaller than the value being scrolled / incremented
by. This results in the email selector wrapping around from the top to
the bottom most email in the mailbox folder due to changes in ec150f0
'store: fix Select behaviour'.

Signed-off-by: akspecs <akspecs@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
akspecs 2022-07-23 21:03:44 -05:00 committed by Robin Jarry
parent 4036f696ad
commit 0f86666f52
1 changed files with 5 additions and 1 deletions

View File

@ -676,7 +676,11 @@ func (store *MessageStore) NextPrev(delta int) {
return return
} }
idx := store.SelectedIndex() + delta idx := store.SelectedIndex() + delta
if idx < 0 {
store.Select(0)
} else {
store.Select(idx) store.Select(idx)
}
store.updateVisual() store.updateVisual()
nextResultIndex := len(store.results) - store.resultIndex - 2*delta nextResultIndex := len(store.results) - store.resultIndex - 2*delta
if nextResultIndex < 0 || nextResultIndex >= len(store.results) { if nextResultIndex < 0 || nextResultIndex >= len(store.results) {