From 45e506e6aebdfdcb743d2d861eaddb85a01b3d5b Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Fri, 12 Aug 2022 23:15:43 +0200 Subject: 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 Tested-by: Tim Culverhouse --- commands/msg/delete.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'commands/msg/delete.go') diff --git a/commands/msg/delete.go b/commands/msg/delete.go index 9db850ec..ee682a47 100644 --- a/commands/msg/delete.go +++ b/commands/msg/delete.go @@ -59,7 +59,7 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error { // no more messages in the list if next == nil { aerc.RemoveTab(h.msgProvider) - acct.Messages().Select(0) + acct.Messages().Select(-1) acct.Messages().Invalidate() return } @@ -77,7 +77,7 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error { if next == nil { // We deleted the last message, select the new last message // instead of the first message - acct.Messages().Select(0) + acct.Messages().Select(-1) } } case *types.Error: @@ -98,10 +98,13 @@ func findNextNonDeleted(deleted []uint32, store *lib.MessageStore) *models.Messa var next, previous *models.MessageInfo stepper := []func(){store.Next, store.Prev} for _, stepFn := range stepper { + previous = nil for { next = store.Selected() if next != nil && !contains(deleted, next.Uid) { - return next + if _, deleted := store.Deleted[next.Uid]; !deleted { + return next + } } if next == nil || previous == next { break -- cgit