Gim/internal/action/repeat.go
Hayden Hargreaves 0e8bb50c20 feat: implemented and tested the dot operator.
The content gets stored in the '.' register.
2026-03-31 18:26:18 -07:00

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}
}