From 0f86666f52620051aaf10cc85c4cacc20af383cb Mon Sep 17 00:00:00 2001 From: akspecs Date: Sat, 23 Jul 2022 21:03:44 -0500 Subject: 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 Acked-by: Robin Jarry --- lib/msgstore.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/msgstore.go b/lib/msgstore.go index 3a78e9e1..34c26761 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -676,7 +676,11 @@ func (store *MessageStore) NextPrev(delta int) { return } idx := store.SelectedIndex() + delta - store.Select(idx) + if idx < 0 { + store.Select(0) + } else { + store.Select(idx) + } store.updateVisual() nextResultIndex := len(store.results) - store.resultIndex - 2*delta if nextResultIndex < 0 || nextResultIndex >= len(store.results) { -- cgit