mark: fix (un)mark -a when no message is selected

Call SelectedMessage() in the mark command only when the uid of the
currently selected message is actually needed. If no message is
selected, i.e. after some filter operations where the previously
selected message is not in the results, 'mark -a' would fail since no
message is selected and an error is returned from SelectedMessage() even
though this is not necessary to mark or unmark all messages.

Reported-by:  Bence Ferdinandy <bence@ferdinandy.com>
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Tim Culverhouse <tim@timculverhouse.com>
This commit is contained in:
Koni Marti 2022-09-27 22:22:20 +02:00 committed by Robin Jarry
parent 9c0e54f9d9
commit 7701f22bf0

View file

@ -23,10 +23,17 @@ func (Mark) Complete(aerc *widgets.Aerc, args []string) []string {
func (Mark) Execute(aerc *widgets.Aerc, args []string) error { func (Mark) Execute(aerc *widgets.Aerc, args []string) error {
h := newHelper(aerc) h := newHelper(aerc)
OnSelectedMessage := func(fn func(uint32)) error {
if fn == nil {
return fmt.Errorf("no operation selected")
}
selected, err := h.msgProvider.SelectedMessage() selected, err := h.msgProvider.SelectedMessage()
if err != nil { if err != nil {
return err return err
} }
fn(selected.Uid)
return nil
}
store, err := h.store() store, err := h.store()
if err != nil { if err != nil {
return err return err
@ -97,7 +104,7 @@ func (Mark) Execute(aerc *widgets.Aerc, args []string) error {
modFunc(uid) modFunc(uid)
} }
} else { } else {
modFunc(selected.Uid) return OnSelectedMessage(modFunc)
} }
return nil return nil
} }
@ -123,7 +130,7 @@ func (Mark) Execute(aerc *widgets.Aerc, args []string) error {
marker.Unmark(uid) marker.Unmark(uid)
} }
} else { } else {
marker.Unmark(selected.Uid) return OnSelectedMessage(marker.Unmark)
} }
return nil return nil
} }