store: fix Select behavior

Fix the behavior of the Select(index int) method to select the last
message if an index > len(list) or select from bottom of list for
negative indexes.

Thanks: akspecs <akspecs@gmail.com>
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Tim Culverhouse 2022-07-23 21:03:42 -05:00 committed by Robin Jarry
parent 9203c4b6ef
commit f8e6478d46
1 changed files with 13 additions and 6 deletions

View File

@ -503,12 +503,19 @@ func (store *MessageStore) SelectedIndex() int {
} }
func (store *MessageStore) Select(index int) { func (store *MessageStore) Select(index int) {
uids := store.Uids() l := len(store.Uids())
store.selected = index switch {
if store.selected < 0 { case l+index < 0:
store.selected = len(uids) - 1 // negative index overruns length of list
} else if store.selected > len(uids) { store.selected = 0
store.selected = len(uids) case index < 0:
// negative index, select from bottom
store.selected = l + index
case index >= l:
// index greater than length, select last
store.selected = l - 1
default:
store.selected = index
} }
store.updateVisual() store.updateVisual()
} }