delete: improve find next function

Improve the function to find the next valid message after the delete
operation. This ensures that messages at the end or when marked in the
visual mode are properly dealt with.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Koni Marti 2022-07-26 11:30:27 +02:00 committed by Robin Jarry
parent 8f7695fde5
commit d941960fe1
1 changed files with 16 additions and 8 deletions

View File

@ -89,16 +89,24 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error {
} }
func findNextNonDeleted(deleted []uint32, store *lib.MessageStore) *models.MessageInfo { func findNextNonDeleted(deleted []uint32, store *lib.MessageStore) *models.MessageInfo {
selected := store.Selected() var next, previous *models.MessageInfo
if !contains(deleted, selected.Uid) { stepper := []func(){store.Next, store.Prev}
return selected for _, stepFn := range stepper {
for {
next = store.Selected()
if next != nil && !contains(deleted, next.Uid) {
return next
}
if next == nil || previous == next {
break
}
stepFn()
previous = next
}
} }
store.Next() if next != nil {
next := store.Selected() store.Select(next.Uid)
if next == selected || next == nil {
// the last message is in the deleted state or doesn't exist
return nil
} }
return next return next
} }