From 4036f696ad359d503922c67b3a32d212a1bda987 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Sat, 23 Jul 2022 21:03:43 -0500 Subject: msgstore: refactor NextPrev Refactor NextPrev to use already existing selection methods and bounds checking Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- lib/msgstore.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/msgstore.go b/lib/msgstore.go index 42795afb..3a78e9e1 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -675,13 +675,8 @@ func (store *MessageStore) NextPrev(delta int) { if len(uids) == 0 { return } - store.selected += delta - if store.selected < 0 { - store.selected = 0 - } - if store.selected >= len(uids) { - store.selected = len(uids) - 1 - } + idx := store.SelectedIndex() + delta + store.Select(idx) store.updateVisual() nextResultIndex := len(store.results) - store.resultIndex - 2*delta if nextResultIndex < 0 || nextResultIndex >= len(store.results) { -- cgit