Gim/internal/motion/search.go
2026-04-09 14:36:18 -07:00

38 lines
1.2 KiB
Go

package motion
import (
"git.gophernest.net/azpect/TextEditor/internal/action"
"git.gophernest.net/azpect/TextEditor/internal/core"
tea "github.com/charmbracelet/bubbletea"
)
// MoveSearchLeft implements Motion - moves cursor left in search line.
type MoveSearchLeft struct{}
// MoveSearchLeft.Execute: Moves the search line cursor one position to the left.
func (a MoveSearchLeft) Execute(m action.Model) tea.Cmd {
search := m.SearchState()
search.Cursor = max(0, search.Cursor-1)
m.SetSearchState(search)
return nil
}
// MoveSearchLeft.Type: Returns CharwiseExclusive for search line motion.
func (a MoveSearchLeft) Type() core.MotionType { return core.CharwiseExclusive }
// MoveSearchRight implements Motion - moves cursor right in search line.
type MoveSearchRight struct{}
// MoveSearchRight.Execute: Moves the search line cursor one position to the right.
func (a MoveSearchRight) Execute(m action.Model) tea.Cmd {
search := m.SearchState()
search.Cursor = min(search.Cursor+1, len(search.Query))
m.SetSearchState(search)
return nil
}
// MoveSearchRight.Type: Returns CharwiseExclusive for search line motion.
func (a MoveSearchRight) Type() core.MotionType { return core.CharwiseExclusive }