diff options
Diffstat (limited to 'commands')
-rw-r--r-- | commands/msg/delete.go | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/commands/msg/delete.go b/commands/msg/delete.go index d1443887..ce5c4ca5 100644 --- a/commands/msg/delete.go +++ b/commands/msg/delete.go @@ -89,16 +89,24 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error { } func findNextNonDeleted(deleted []uint32, store *lib.MessageStore) *models.MessageInfo { - selected := store.Selected() - if !contains(deleted, selected.Uid) { - return selected + var next, previous *models.MessageInfo + stepper := []func(){store.Next, store.Prev} + 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() - next := store.Selected() - if next == selected || next == nil { - // the last message is in the deleted state or doesn't exist - return nil + if next != nil { + store.Select(next.Uid) } return next } |