124 lines
2.3 KiB
Go
124 lines
2.3 KiB
Go
package action
|
|
|
|
import tea "github.com/charmbracelet/bubbletea"
|
|
|
|
// EnterInsert implements Action (i)
|
|
type EnterInsert struct {
|
|
Count int
|
|
}
|
|
|
|
func (a EnterInsert) Execute(m Model) tea.Cmd {
|
|
// Start recording
|
|
m.SetInsertRecording(a.Count, a)
|
|
m.SetMode(InsertMode)
|
|
return nil
|
|
}
|
|
|
|
func (a EnterInsert) WithCount(n int) Action {
|
|
return EnterInsert{Count: n}
|
|
}
|
|
|
|
// EnterInsertAfter implements Action (a)
|
|
type EnterInsertAfter struct {
|
|
Count int
|
|
}
|
|
|
|
func (a EnterInsertAfter) Execute(m Model) tea.Cmd {
|
|
m.SetCursorX(m.CursorX() + 1)
|
|
m.ClampCursorX()
|
|
|
|
// Start recording
|
|
m.SetInsertRecording(a.Count, a)
|
|
m.SetMode(InsertMode)
|
|
return nil
|
|
}
|
|
|
|
func (a EnterInsertAfter) WithCount(n int) Action {
|
|
return EnterInsertAfter{Count: n}
|
|
}
|
|
|
|
// EnterInsertLineStart implements Action (I)
|
|
type EnterInsertLineStart struct {
|
|
Count int
|
|
}
|
|
|
|
func (a EnterInsertLineStart) Execute(m Model) tea.Cmd {
|
|
m.SetCursorX(0)
|
|
m.ClampCursorX()
|
|
|
|
// Start recording
|
|
m.SetInsertRecording(a.Count, a)
|
|
m.SetMode(InsertMode)
|
|
return nil
|
|
}
|
|
|
|
func (a EnterInsertLineStart) WithCount(n int) Action {
|
|
return EnterInsertLineStart{Count: n}
|
|
}
|
|
|
|
// EnterInsertLineEnd implements Action (A)
|
|
type EnterInsertLineEnd struct {
|
|
Count int
|
|
}
|
|
|
|
func (a EnterInsertLineEnd) Execute(m Model) tea.Cmd {
|
|
m.SetCursorX(len(m.Line(m.CursorY())))
|
|
m.ClampCursorX()
|
|
|
|
// Start recording
|
|
m.SetInsertRecording(a.Count, a)
|
|
m.SetMode(InsertMode)
|
|
return nil
|
|
}
|
|
|
|
func (a EnterInsertLineEnd) WithCount(n int) Action {
|
|
return EnterInsertLineEnd{Count: n}
|
|
}
|
|
|
|
// OpenLineBelow implements Action (o)
|
|
type OpenLineBelow struct {
|
|
Count int
|
|
}
|
|
|
|
func (a OpenLineBelow) Execute(m Model) tea.Cmd {
|
|
pos := m.CursorY()
|
|
|
|
if pos >= m.LineCount() {
|
|
m.InsertLine(m.LineCount(), "")
|
|
} else {
|
|
m.InsertLine(pos+1, "")
|
|
}
|
|
|
|
m.SetCursorY(m.CursorY() + 1)
|
|
m.SetCursorX(0)
|
|
|
|
// Start recording
|
|
m.SetInsertRecording(a.Count, a)
|
|
m.SetMode(InsertMode)
|
|
return nil
|
|
}
|
|
|
|
func (a OpenLineBelow) WithCount(n int) Action {
|
|
return OpenLineBelow{Count: n}
|
|
}
|
|
|
|
// OpenLineAbove implements Action (O)
|
|
type OpenLineAbove struct {
|
|
Count int
|
|
}
|
|
|
|
func (a OpenLineAbove) Execute(m Model) tea.Cmd {
|
|
pos := m.CursorY()
|
|
m.InsertLine(pos, "")
|
|
m.SetCursorX(0)
|
|
|
|
// Start recording
|
|
m.SetInsertRecording(a.Count, a)
|
|
m.SetMode(InsertMode)
|
|
return nil
|
|
}
|
|
|
|
func (a OpenLineAbove) WithCount(n int) Action {
|
|
return OpenLineAbove{Count: n}
|
|
}
|