75 lines
1.4 KiB
Go
75 lines
1.4 KiB
Go
package action
|
|
|
|
import tea "github.com/charmbracelet/bubbletea"
|
|
|
|
// Mode constants for editor mode
|
|
type Mode int
|
|
|
|
const (
|
|
NormalMode Mode = iota
|
|
InsertMode
|
|
CommandMode
|
|
VisualMode
|
|
VisualLineMode
|
|
VisualBlockMode
|
|
)
|
|
|
|
// Model defines the interface for editor state that actions can modify
|
|
type Model interface {
|
|
// Text buffer
|
|
Lines() []string
|
|
Line(idx int) string
|
|
SetLine(idx int, content string)
|
|
InsertLine(idx int, content string)
|
|
DeleteLine(idx int)
|
|
LineCount() int
|
|
|
|
// Cursor
|
|
CursorX() int
|
|
CursorY() int
|
|
SetCursorX(x int)
|
|
SetCursorY(y int)
|
|
ClampCursorX()
|
|
|
|
// Anchor
|
|
AnchorX() int
|
|
AnchorY() int
|
|
SetAnchorX(x int)
|
|
SetAnchorY(y int)
|
|
|
|
// Mode
|
|
Mode() Mode
|
|
SetMode(mode Mode)
|
|
IsVisualMode() bool
|
|
|
|
// Insert recording (for count replay)
|
|
SetInsertRecording(count int, action Action)
|
|
}
|
|
|
|
// Position represents a location in the buffer
|
|
type Position struct {
|
|
Line, Col int
|
|
}
|
|
|
|
// Action is the base interface - anything executable
|
|
type Action interface {
|
|
Execute(m Model) tea.Cmd
|
|
}
|
|
|
|
// Motion moves the cursor and returns the range covered
|
|
type Motion interface {
|
|
Action
|
|
}
|
|
|
|
// Operator acts on a range (delete, yank, change)
|
|
type Operator interface {
|
|
Operate(m Model, start, end Position) tea.Cmd
|
|
// DoublePress handles dd, yy, cc (line-wise)
|
|
DoublePress(m Model, count int) tea.Cmd
|
|
}
|
|
|
|
// Repeatable actions track count
|
|
type Repeatable interface {
|
|
WithCount(n int) Action
|
|
}
|