Implement :select-message
This commit is contained in:
parent
db2146bc91
commit
13ba53c9d0
2 changed files with 40 additions and 0 deletions
31
commands/select-message.go
Normal file
31
commands/select-message.go
Normal 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
|
||||
}
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue