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

View file

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