summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2022-07-23 21:03:42 -0500
committerRobin Jarry <robin@jarry.cc>2022-07-24 23:04:52 +0200
commitf8e6478d461c8f8224c49b4186cedd1566b72144 (patch)
tree37010d4d02532e64635e8b9fec42cd9035f24329
parent9203c4b6ef95b324336a9f023550b64a9eb1e4a8 (diff)
downloadaerc-f8e6478d461c8f8224c49b4186cedd1566b72144.zip
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>
-rw-r--r--lib/msgstore.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go
index 52cd739..42795af 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -503,12 +503,19 @@ func (store *MessageStore) SelectedIndex() int {
}
func (store *MessageStore) Select(index int) {
- uids := store.Uids()
- store.selected = index
- if store.selected < 0 {
- store.selected = len(uids) - 1
- } else if store.selected > len(uids) {
- store.selected = len(uids)
+ l := len(store.Uids())
+ switch {
+ case l+index < 0:
+ // negative index overruns length of list
+ store.selected = 0
+ 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()
}