package motion import ( "git.gophernest.net/azpect/TextEditor/internal/action" tea "github.com/charmbracelet/bubbletea" ) // MoveDown implements Motion (j) - linewise type MoveDown struct { Count int } func (a MoveDown) Execute(m action.Model) tea.Cmd { win := m.ActiveWindow() buf := m.ActiveBuffer() for i := 0; i < a.Count && win.Cursor.Line < buf.LineCount()-1; i++ { win.SetCursorLine(win.Cursor.Line + 1) } return nil } func (a MoveDown) Type() action.MotionType { return action.Linewise } func (a MoveDown) WithCount(n int) action.Action { return MoveDown{Count: n} } // MoveUp implements Motion (k) - linewise type MoveUp struct { Count int } func (a MoveUp) Execute(m action.Model) tea.Cmd { win := m.ActiveWindow() for i := 0; i < a.Count && win.Cursor.Line > 0; i++ { win.SetCursorLine(win.Cursor.Line - 1) } return nil } func (a MoveUp) Type() action.MotionType { return action.Linewise } func (a MoveUp) WithCount(n int) action.Action { return MoveUp{Count: n} } // MoveLeft implements Motion (h) - charwise type MoveLeft struct { Count int } func (a MoveLeft) Execute(m action.Model) tea.Cmd { win := m.ActiveWindow() for i := 0; i < a.Count && win.Cursor.Col > 0; i++ { win.SetCursorCol(win.Cursor.Col - 1) } return nil } func (a MoveLeft) Type() action.MotionType { return action.CharwiseExclusive } func (a MoveLeft) WithCount(n int) action.Action { return MoveLeft{Count: n} } // MoveRight implements Motion (l) - charwise type MoveRight struct { Count int } func (a MoveRight) Execute(m action.Model) tea.Cmd { win := m.ActiveWindow() buf := m.ActiveBuffer() lineLen := len(buf.Lines[win.Cursor.Line]) for i := 0; i < a.Count && win.Cursor.Col <= lineLen; i++ { win.SetCursorCol(win.Cursor.Col + 1) } return nil } func (a MoveRight) Type() action.MotionType { return action.CharwiseExclusive } func (a MoveRight) WithCount(n int) action.Action { return MoveRight{Count: n} }