Gim/internal/motion/jump.go
2026-02-10 22:20:03 -07:00

66 lines
1.2 KiB
Go

package motion
import (
"git.gophernest.net/azpect/TextEditor/internal/action"
tea "github.com/charmbracelet/bubbletea"
)
// MoveToTop implements Motion (gg)
type MoveToTop struct{}
func (a MoveToTop) Execute(m action.Model) tea.Cmd {
m.SetCursorY(0)
m.ClampCursorX()
return nil
}
// MoveToBottom implements Motion (G)
type MoveToBottom struct{}
func (a MoveToBottom) Execute(m action.Model) tea.Cmd {
m.SetCursorY(m.LineCount() - 1)
m.ClampCursorX()
return nil
}
// MoveToLineStart implements Motion (0)
type MoveToLineStart struct{}
func (a MoveToLineStart) Execute(m action.Model) tea.Cmd {
m.SetCursorX(0)
m.ClampCursorX()
return nil
}
// MoveToLineEnd implements Motion ($)
type MoveToLineEnd struct{}
func (a MoveToLineEnd) Execute(m action.Model) tea.Cmd {
m.SetCursorX(len(m.Line(m.CursorY())))
m.ClampCursorX()
return nil
}
// MoveToLineContentStart implements Motion (_)
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
}