Implement :select-message

This commit is contained in:
Drew DeVault 2019-03-15 22:01:20 -04:00
parent db2146bc91
commit 13ba53c9d0
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,31 @@
package commands
import (
"errors"
"strconv"
"git.sr.ht/~sircmpwn/aerc2/widgets"
)
func init() {
Register("select-message", SelectMessage)
}
func SelectMessage(aerc *widgets.Aerc, args []string) error {
if len(args) != 2 {
return errors.New("Usage: :select-message <n>")
}
var (
n int = 1
err error
)
if len(args) > 1 {
n, err = strconv.Atoi(args[1])
if err != nil {
return errors.New("Usage: :select-message <n>")
}
}
acct := aerc.SelectedAccount()
acct.Messages().Select(n)
return nil
}

View File

@ -112,6 +112,15 @@ func (ml *MessageList) SetStore(store *lib.MessageStore) {
ml.Invalidate()
}
func (ml *MessageList) Select(index int) {
ml.selected = index
for ; ml.selected < 0; ml.selected = len(ml.store.Uids) + ml.selected {
}
if ml.selected > len(ml.store.Uids) {
ml.selected = len(ml.store.Uids)
}
}
func (ml *MessageList) nextPrev(delta int) {
ml.selected += delta
if ml.selected < 0 {