Implement next-message in msgview using account
This makes sure that the next-message command accepts the same arguments in the account view and the msgview
This commit is contained in:
parent
3650b72ca6
commit
507c90537c
2 changed files with 37 additions and 28 deletions
|
@ -24,8 +24,20 @@ func (_ NextPrevMsg) Complete(aerc *widgets.Aerc, args []string) []string {
|
|||
}
|
||||
|
||||
func (_ NextPrevMsg) Execute(aerc *widgets.Aerc, args []string) error {
|
||||
var err, n, pct = ParseNextPrevMessage(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
acct := aerc.SelectedAccount()
|
||||
if acct == nil {
|
||||
return errors.New("No account selected")
|
||||
}
|
||||
return ExecuteNextPrevMessage(args, acct, pct, n)
|
||||
}
|
||||
|
||||
func ParseNextPrevMessage(args []string) (error, int, bool) {
|
||||
if len(args) > 2 {
|
||||
return nextPrevMessageUsage(args[0])
|
||||
return nextPrevMessageUsage(args[0]), 0, false
|
||||
}
|
||||
var (
|
||||
n int = 1
|
||||
|
@ -39,31 +51,29 @@ func (_ NextPrevMsg) Execute(aerc *widgets.Aerc, args []string) error {
|
|||
}
|
||||
n, err = strconv.Atoi(args[1])
|
||||
if err != nil {
|
||||
return nextPrevMessageUsage(args[0])
|
||||
return nextPrevMessageUsage(args[0]), 0, false
|
||||
}
|
||||
}
|
||||
acct := aerc.SelectedAccount()
|
||||
if acct == nil {
|
||||
return errors.New("No account selected")
|
||||
return nil, n, pct
|
||||
}
|
||||
|
||||
func ExecuteNextPrevMessage(args []string, acct *widgets.AccountView, pct bool, n int) error {
|
||||
if pct {
|
||||
n = int(float64(acct.Messages().Height()) * (float64(n) / 100.0))
|
||||
}
|
||||
for ; n > 0; n-- {
|
||||
if args[0] == "prev-message" || args[0] == "prev" {
|
||||
store := acct.Store()
|
||||
if store != nil {
|
||||
store.Prev()
|
||||
store.NextPrev(-n)
|
||||
}
|
||||
acct.Messages().Scroll()
|
||||
} else {
|
||||
store := acct.Store()
|
||||
if store != nil {
|
||||
store.Next()
|
||||
store.NextPrev(n)
|
||||
}
|
||||
acct.Messages().Scroll()
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package msgview
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.sr.ht/~sircmpwn/aerc/commands/account"
|
||||
"git.sr.ht/~sircmpwn/aerc/widgets"
|
||||
)
|
||||
|
||||
|
@ -21,16 +20,16 @@ func (_ NextPrevMsg) Complete(aerc *widgets.Aerc, args []string) []string {
|
|||
}
|
||||
|
||||
func (_ NextPrevMsg) Execute(aerc *widgets.Aerc, args []string) error {
|
||||
err, n, pct := account.ParseNextPrevMessage(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mv, _ := aerc.SelectedTab().(*widgets.MessageViewer)
|
||||
acct := mv.SelectedAccount()
|
||||
store := mv.Store()
|
||||
if acct == nil {
|
||||
return errors.New("No account selected")
|
||||
}
|
||||
if args[0] == "prev-message" || args[0] == "prev" {
|
||||
store.Prev()
|
||||
} else {
|
||||
store.Next()
|
||||
err = account.ExecuteNextPrevMessage(args, acct, pct, n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
nextMsg := store.Selected()
|
||||
if nextMsg == nil {
|
||||
|
|
Loading…
Reference in a new issue