aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2023-08-30 16:18:00 -0500
committerRobin Jarry <robin@jarry.cc>2023-08-31 17:36:34 +0200
commit83bd28cde61e6663a98e02c7bc769e374df5a6f0 (patch)
tree58b94445013233ab7692196942336482d721ba5c
parent9ba1c3408c34d1b9da343b00ea963d23138d5037 (diff)
downloadaerc-83bd28cde61e6663a98e02c7bc769e374df5a6f0.tar.gz
msgstore: ensure selection when calling sort
When using notmuch and changing labels, there is no reselection logic as there is when using a :mv command for other backends. This results in any label change that removes the message from the current query in having no selection. Add some simple reselection logic in the Sort callback so any call to Sort (which will refresh the message list) ensures the previously selected message is still selected, and if it isn't in the store anymore we select the same index of message as was previously selected. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Tested-by: Inwit <inwit@sindominio.net> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--lib/msgstore.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go
index a29ff139..01b78289 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -813,8 +813,13 @@ func (store *MessageStore) Sort(criteria []*types.SortCriterion, cb func(types.W
store.sortCriteria = criteria
store.Sorting = true
+ idx := len(store.Uids()) - (store.SelectedIndex() + 1)
handle_return := func(msg types.WorkerMessage) {
store.Select(store.SelectedUid())
+ if store.SelectedIndex() < 0 {
+ store.Select(MagicUid)
+ store.NextPrev(idx)
+ }
store.Sorting = false
if cb != nil {
cb(msg)