package action import ( "git.gophernest.net/azpect/TextEditor/internal/core" tea "github.com/charmbracelet/bubbletea" ) type ReplaceChar struct { Char string Count int } func (m ReplaceChar) WithChar(char string) Motion { m.Char = char return m } func (m ReplaceChar) Type() core.MotionType { return core.CharwiseInclusive } // WithCount sets the count (required by Repeatable interface) func (m ReplaceChar) WithCount(n int) Action { m.Count = n return m } func (a ReplaceChar) Execute(m Model) tea.Cmd { win := m.ActiveWindow() buf := m.ActiveBuffer() if buf.UndoStack != nil && !buf.UndoStack.Recording() { buf.UndoStack.BeginBlock(win.Cursor) } pos := win.Cursor.Col line := buf.Line(win.Cursor.Line) for i := 0; i < a.Count && pos < len(line); i++ { line = line[:pos] + a.Char + line[pos+1:] buf.SetLine(win.Cursor.Line, line) pos++ } win.SetCursorCol(pos - 1) m.SetMode(core.NormalMode) if buf.UndoStack != nil { buf.UndoStack.EndBlock(win.Cursor) } return nil } type EnterReplace struct { Count int } func (a EnterReplace) WithCount(n int) Action { a.Count = n return a } func (a EnterReplace) Execute(m Model) tea.Cmd { m.SetCommandOutput(&core.CommandOutput{ Lines: []string{"Replace mode (R) not implemented yet"}, Inline: true, IsError: true, }) return nil }