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:
parent
8f7695fde5
commit
d941960fe1
1 changed files with 16 additions and 8 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue