delete: fix find-next function

Fixes the find-next-loop when deleting the last message. The reverse
loop with store.Prev() will break too early because the value of
'previous' was not reset correctly.

Fixes: d941960f "delete: improve find next function"
References: https://todo.sr.ht/~rjarry/aerc/59
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
This commit is contained in:
Koni Marti 2022-08-12 23:15:43 +02:00 committed by Robin Jarry
parent 588be1a284
commit 45e506e6ae
1 changed files with 6 additions and 3 deletions

View File

@ -59,7 +59,7 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error {
// no more messages in the list
if next == nil {
aerc.RemoveTab(h.msgProvider)
acct.Messages().Select(0)
acct.Messages().Select(-1)
acct.Messages().Invalidate()
return
}
@ -77,7 +77,7 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error {
if next == nil {
// We deleted the last message, select the new last message
// instead of the first message
acct.Messages().Select(0)
acct.Messages().Select(-1)
}
}
case *types.Error:
@ -98,10 +98,13 @@ func findNextNonDeleted(deleted []uint32, store *lib.MessageStore) *models.Messa
var next, previous *models.MessageInfo
stepper := []func(){store.Next, store.Prev}
for _, stepFn := range stepper {
previous = nil
for {
next = store.Selected()
if next != nil && !contains(deleted, next.Uid) {
return next
if _, deleted := store.Deleted[next.Uid]; !deleted {
return next
}
}
if next == nil || previous == next {
break