Implement :{next,prev}-field in compose view
This commit is contained in:
parent
2a4dd5cb87
commit
f37508a539
6 changed files with 70 additions and 5 deletions
3
aerc.go
3
aerc.go
|
@ -12,6 +12,7 @@ import (
|
|||
"git.sr.ht/~sircmpwn/aerc2/config"
|
||||
"git.sr.ht/~sircmpwn/aerc2/commands"
|
||||
"git.sr.ht/~sircmpwn/aerc2/commands/account"
|
||||
"git.sr.ht/~sircmpwn/aerc2/commands/compose"
|
||||
"git.sr.ht/~sircmpwn/aerc2/commands/msgview"
|
||||
"git.sr.ht/~sircmpwn/aerc2/commands/terminal"
|
||||
libui "git.sr.ht/~sircmpwn/aerc2/lib/ui"
|
||||
|
@ -27,7 +28,7 @@ func getCommands(selected libui.Drawable) []*commands.Commands {
|
|||
}
|
||||
case *widgets.Composer:
|
||||
return []*commands.Commands{
|
||||
// TODO: compose-specific commands
|
||||
compose.ComposeCommands,
|
||||
commands.GlobalCommands,
|
||||
}
|
||||
case *widgets.MessageViewer:
|
||||
|
|
16
commands/compose/compose.go
Normal file
16
commands/compose/compose.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package compose
|
||||
|
||||
import (
|
||||
"git.sr.ht/~sircmpwn/aerc2/commands"
|
||||
)
|
||||
|
||||
var (
|
||||
ComposeCommands *commands.Commands
|
||||
)
|
||||
|
||||
func register(name string, cmd commands.AercCommand) {
|
||||
if ComposeCommands == nil {
|
||||
ComposeCommands = commands.NewCommands()
|
||||
}
|
||||
ComposeCommands.Register(name, cmd)
|
||||
}
|
30
commands/compose/next-field.go
Normal file
30
commands/compose/next-field.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package compose
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.sr.ht/~sircmpwn/aerc2/widgets"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register("next-field", NextPrevField)
|
||||
register("prev-field", NextPrevField)
|
||||
}
|
||||
|
||||
func nextPrevFieldUsage(cmd string) error {
|
||||
return errors.New(fmt.Sprintf("Usage: %s", cmd))
|
||||
}
|
||||
|
||||
func NextPrevField(aerc *widgets.Aerc, args []string) error {
|
||||
if len(args) > 2 {
|
||||
return nextPrevFieldUsage(args[0])
|
||||
}
|
||||
composer, _ := aerc.SelectedTab().(*widgets.Composer)
|
||||
if args[0] == "prev-field" {
|
||||
composer.PrevField()
|
||||
} else {
|
||||
composer.NextField()
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -47,9 +47,9 @@ func (ti *TextInput) Draw(ctx *Context) {
|
|||
ti.ctx = ctx // gross
|
||||
ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
|
||||
ctx.Printf(0, 0, tcell.StyleDefault, "%s%s", ti.prompt, string(ti.text))
|
||||
cells := runewidth.StringWidth(string(ti.text[:ti.index]))
|
||||
if cells != ti.cells {
|
||||
ctx.SetCursor(cells+1, 0)
|
||||
cells := runewidth.StringWidth(string(ti.text[:ti.index]) + ti.prompt)
|
||||
if cells != ti.cells && ti.focus {
|
||||
ctx.SetCursor(cells, 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ func NewComposer() *Composer {
|
|||
grid: grid,
|
||||
editor: term,
|
||||
// You have to backtab to get to "From", since you usually don't edit it
|
||||
focused: 3,
|
||||
focused: 1,
|
||||
focusable: []ui.DrawableInteractive{
|
||||
from,
|
||||
to,
|
||||
|
@ -99,6 +99,21 @@ func (c *Composer) Focus(focus bool) {
|
|||
c.focusable[c.focused].Focus(focus)
|
||||
}
|
||||
|
||||
func (c *Composer) PrevField() {
|
||||
c.focusable[c.focused].Focus(false)
|
||||
c.focused--
|
||||
if c.focused == -1 {
|
||||
c.focused = len(c.focusable) - 1
|
||||
}
|
||||
c.focusable[c.focused].Focus(true)
|
||||
}
|
||||
|
||||
func (c *Composer) NextField() {
|
||||
c.focusable[c.focused].Focus(false)
|
||||
c.focused = (c.focused + 1) % len(c.focusable)
|
||||
c.focusable[c.focused].Focus(true)
|
||||
}
|
||||
|
||||
func newHeaderEditor(name string, value string) *headerEditor {
|
||||
return &headerEditor{
|
||||
input: ui.NewTextInput(value),
|
||||
|
|
|
@ -273,6 +273,8 @@ func (term *Terminal) Draw(ctx *ui.Context) {
|
|||
if ctx.Width() != cols || ctx.Height() != rows {
|
||||
pty.Setsize(term.pty, &winsize)
|
||||
term.vterm.SetSize(ctx.Height(), ctx.Width())
|
||||
rect := vterm.NewRect(0, ctx.Width(), 0, ctx.Height())
|
||||
term.damage = append(term.damage, *rect)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -333,6 +335,7 @@ func (term *Terminal) Focus(focus bool) {
|
|||
state := term.vterm.ObtainState()
|
||||
row, col := state.GetCursorPos()
|
||||
term.ctx.SetCursor(col, row)
|
||||
term.Invalidate()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue