42 lines
802 B
Go
42 lines
802 B
Go
package action
|
|
|
|
import (
|
|
"git.gophernest.net/azpect/TextEditor/internal/core"
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
)
|
|
|
|
// Repeat implements Action (.) - repeat last input
|
|
type Repeat struct {
|
|
Count int
|
|
}
|
|
|
|
func (a Repeat) Execute(m Model) tea.Cmd {
|
|
keys := m.LastChangeKeys()
|
|
|
|
if len(keys) == 1 && keys[0] == "." {
|
|
m.SetCommandOutput(&core.CommandOutput{
|
|
Lines: []string{"Cannot repeat '.'"},
|
|
Inline: true,
|
|
IsError: true,
|
|
})
|
|
|
|
return nil
|
|
}
|
|
|
|
var cmds []tea.Cmd
|
|
for _, key := range keys {
|
|
cmd := m.HandleKey(key)
|
|
cmds = append(cmds, cmd)
|
|
}
|
|
|
|
return tea.Batch(cmds...)
|
|
}
|
|
|
|
// Ensure Repeat implements Repeatable
|
|
var _ Repeatable = Repeat{}
|
|
|
|
// Repeat.WithCount: Returns a new Repeat with the given count.
|
|
func (a Repeat) WithCount(n int) Action {
|
|
return Repeat{Count: n}
|
|
}
|