From 83bd28cde61e6663a98e02c7bc769e374df5a6f0 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Wed, 30 Aug 2023 16:18:00 -0500 Subject: 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 Tested-by: Inwit Acked-by: Robin Jarry --- lib/msgstore.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib') 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) -- cgit