package motion import ( "git.gophernest.net/azpect/TextEditor/internal/action" tea "github.com/charmbracelet/bubbletea" ) // MoveToTop implements Motion (gg) - linewise type MoveToTop struct{} func (a MoveToTop) Execute(m action.Model) tea.Cmd { m.SetCursorY(0) m.ClampCursorX() return nil } func (a MoveToTop) Type() action.MotionType { return action.Linewise } // MoveToBottom implements Motion (G) - linewise type MoveToBottom struct{} func (a MoveToBottom) Execute(m action.Model) tea.Cmd { m.SetCursorY(m.LineCount() - 1) m.ClampCursorX() return nil } func (a MoveToBottom) Type() action.MotionType { return action.Linewise } // MoveToLineStart implements Motion (0) - charwise type MoveToLineStart struct{} func (a MoveToLineStart) Execute(m action.Model) tea.Cmd { m.SetCursorX(0) m.ClampCursorX() return nil } func (a MoveToLineStart) Type() action.MotionType { return action.Charwise } // MoveToLineEnd implements Motion ($) - charwise type MoveToLineEnd struct{} func (a MoveToLineEnd) Execute(m action.Model) tea.Cmd { m.SetCursorX(len(m.Line(m.CursorY()))) m.ClampCursorX() return nil } func (a MoveToLineEnd) Type() action.MotionType { return action.Charwise } // MoveToLineContentStart implements Motion (_) - charwise type MoveToLineContentStart struct{} func (a MoveToLineContentStart) Execute(m action.Model) tea.Cmd { line := m.Line(m.CursorY()) x := 0 for x < len(line) { ch := line[x] if ch != ' ' && ch != '\t' { break } x++ } // If we are on the last char, we overflew, back once if x == len(line) && x > 0 { x-- } m.SetCursorX(x) return nil } func (a MoveToLineContentStart) Type() action.MotionType { return action.Charwise }