summaryrefslogtreecommitdiff
path: root/commands
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-07-26 11:30:27 +0200
committerRobin Jarry <robin@jarry.cc>2022-07-26 11:34:31 +0200
commitd941960fe175fd89b08b5a3f1bd073e0ecaf2d59 (patch)
tree214d7d91a3ff7c923df80dde37c0d70d6b559d02 /commands
parent8f7695fde5cd84b7f6b8f3193270eda2fd62448c (diff)
downloadaerc-d941960fe175fd89b08b5a3f1bd073e0ecaf2d59.zip
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>
Diffstat (limited to 'commands')
-rw-r--r--commands/msg/delete.go24
1 files changed, 16 insertions, 8 deletions
diff --git a/commands/msg/delete.go b/commands/msg/delete.go
index d144388..ce5c4ca 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
}