From b1b3edf81037fd047906b890bb5a75f9df395588 Mon Sep 17 00:00:00 2001 From: Hayden Hargreaves Date: Thu, 26 Feb 2026 23:18:18 -0700 Subject: [PATCH] feat: this is huge, and needs some review, but for now its good The tests are not passing, something to do with view I think. --- cmd/gim/main.go | 24 +- internal/action/change.go | 36 +- internal/action/delete.go | 46 +- internal/action/insert.go | 139 +++-- internal/action/misc.go | 15 +- internal/action/paste.go | 145 +++-- internal/action/window.go | 7 + internal/editor/helpers_example_test.go | 42 +- internal/editor/helpers_test.go | 29 +- internal/editor/integration_delete_test.go | 172 ++--- internal/editor/integration_insert_test.go | 360 +++++------ .../editor/integration_motion_basic_test.go | 96 +-- .../editor/integration_motion_jump_test.go | 248 ++++---- .../editor/integration_motion_word_test.go | 582 ++++++++--------- .../integration_operator_change_test.go | 304 ++++----- .../integration_operator_delete_test.go | 588 +++++++++--------- internal/editor/integration_paste_test.go | 568 ++++++++--------- internal/editor/integration_scroll_test.go | 172 ++--- internal/editor/integration_visual_test.go | 272 ++++---- internal/editor/integration_yank_test.go | 176 +++--- internal/editor/model.go | 13 + internal/editor/model_builder.go | 7 + internal/editor/style.go | 151 +++-- internal/editor/update.go | 3 +- internal/editor/view.go | 82 +-- internal/input/handler.go | 18 +- internal/motion/basic.go | 30 +- internal/motion/jump.go | 71 ++- internal/motion/word.go | 113 ++-- internal/operator/change.go | 68 +- internal/operator/delete.go | 72 ++- internal/operator/yank.go | 39 +- 32 files changed, 2469 insertions(+), 2219 deletions(-) diff --git a/cmd/gim/main.go b/cmd/gim/main.go index 50c3c96..0ef6d2b 100644 --- a/cmd/gim/main.go +++ b/cmd/gim/main.go @@ -1,6 +1,8 @@ package main import ( + "fmt" + "git.gophernest.net/azpect/TextEditor/internal/action" "git.gophernest.net/azpect/TextEditor/internal/editor" tea "github.com/charmbracelet/bubbletea" @@ -20,16 +22,16 @@ func main() { WithActiveWindowId(win.Id). Build() - tea.NewProgram(model, tea.WithAltScreen()).Run() + m, _ := tea.NewProgram(model, tea.WithAltScreen()).Run() - // final, ok := m.(*editor.Model) - // if ok { - // fmt.Printf("PRINTING WINDOWS: %+v\n", final.Windows()) - // fmt.Printf("PRINTING ACTIVE WINDOW: %+v\n", final.ActiveWindow()) - // for _, win := range final.Windows() { - // fmt.Printf("\t%+v\n", *win.Buffer) - // } - // } else { - // fmt.Printf("PRINTING ALL: %+v\n", m) - // } + final, ok := m.(*editor.Model) + if ok { + fmt.Printf("PRINTING WINDOWS: %+v\n", final.Windows()) + fmt.Printf("PRINTING ACTIVE WINDOW: %+v\n", final.ActiveWindow()) + for _, win := range final.Windows() { + fmt.Printf("\t%+v\n", *win.Buffer) + } + } else { + fmt.Printf("PRINTING ALL: %+v\n", m) + } } diff --git a/internal/action/change.go b/internal/action/change.go index 0a3a25e..8e410a7 100644 --- a/internal/action/change.go +++ b/internal/action/change.go @@ -8,8 +8,11 @@ type ChangeToEndOfLine struct { } func (a ChangeToEndOfLine) Execute(m Model) tea.Cmd { - pos := m.CursorX() - line := m.Line(m.CursorY()) + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + pos := win.Cursor.Col + line := buf.Lines[win.Cursor.Line] // Save deleted text to register if pos < len(line) { @@ -17,7 +20,7 @@ func (a ChangeToEndOfLine) Execute(m Model) tea.Cmd { } // Delete to end of line - m.SetLine(m.CursorY(), line[:pos]) + buf.SetLine(win.Cursor.Line, line[:pos]) // Enter insert mode m.SetMode(InsertMode) @@ -38,8 +41,11 @@ type SubstituteChar struct { } func (a SubstituteChar) Execute(m Model) tea.Cmd { - pos := m.CursorX() - line := m.Line(m.CursorY()) + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + pos := win.Cursor.Col + line := buf.Lines[win.Cursor.Line] // Calculate how many chars to delete (limited by line length) count := min(a.Count, len(line)-pos) @@ -49,7 +55,7 @@ func (a SubstituteChar) Execute(m Model) tea.Cmd { m.UpdateDefaultRegister(CharwiseRegister, []string{line[pos : pos+count]}) // Delete the characters - m.SetLine(m.CursorY(), line[:pos]+line[pos+count:]) + buf.SetLine(win.Cursor.Line, line[:pos]+line[pos+count:]) } // Enter insert mode @@ -71,29 +77,31 @@ type SubstituteLine struct { } func (a SubstituteLine) Execute(m Model) tea.Cmd { - y := m.CursorY() + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + y := win.Cursor.Line // Calculate how many lines to substitute - count := min(a.Count, m.LineCount()-y) + count := min(a.Count, buf.LineCount()-y) var lines []string // Collect and delete lines for range count { - lines = append(lines, m.Line(y)) - m.DeleteLine(y) + lines = append(lines, buf.Lines[y]) + buf.DeleteLine(y) } // Save deleted lines to register m.UpdateDefaultRegister(LinewiseRegister, lines) // Insert empty line at original position - insertY := min(y, m.LineCount()) - m.InsertLine(insertY, "") + insertY := min(y, buf.LineCount()) + buf.InsertLine(insertY, "") // Position cursor - m.SetCursorY(insertY) - m.SetCursorX(0) + win.SetCursorPos(insertY, 0) // Enter insert mode m.SetMode(InsertMode) diff --git a/internal/action/delete.go b/internal/action/delete.go index 6142417..6d35887 100644 --- a/internal/action/delete.go +++ b/internal/action/delete.go @@ -8,11 +8,14 @@ type DeleteChar struct { } func (a DeleteChar) Execute(m Model) tea.Cmd { - pos := m.CursorX() - line := m.Line(m.CursorY()) + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + pos := win.Cursor.Col + line := buf.Lines[win.Cursor.Line] for i := 0; i < a.Count && pos < len(line); i++ { line = line[:pos] + line[pos+1:] - m.SetLine(m.CursorY(), line) + buf.SetLine(win.Cursor.Line, line) } return nil @@ -27,46 +30,47 @@ type DeleteToEndOfLine struct { } func (a DeleteToEndOfLine) Execute(m Model) tea.Cmd { - // Delete to end of line - pos := m.CursorX() - line := m.Line(m.CursorY()) + win := m.ActiveWindow() + buf := m.ActiveBuffer() - m.SetLine(m.CursorY(), line[:pos]) - m.SetCursorX(pos - 1) + // Delete to end of line + pos := win.Cursor.Col + line := buf.Lines[win.Cursor.Line] + + buf.SetLine(win.Cursor.Line, line[:pos]) + win.SetCursorCol(pos - 1) // If count is greater, than we will delete the next N - 1 lines below - initY := m.CursorY() + initY := win.Cursor.Line if a.Count > 1 { // Copied from `internal/operator/delete.go` - opCount := min(a.Count-1, m.LineCount()-m.CursorY()) + opCount := min(a.Count-1, buf.LineCount()-win.Cursor.Line) // Down one - m.SetCursorY(initY + 1) + win.SetCursorLine(initY + 1) for range opCount { - y := m.CursorY() // Changed from the copied code + y := win.Cursor.Line // Changed from the copied code // Stop if were on the starting line if y == initY { break } - m.DeleteLine(y) + buf.DeleteLine(y) - if m.LineCount() == 0 { - m.InsertLine(0, "") + if buf.LineCount() == 0 { + buf.InsertLine(0, "") } - if y >= m.LineCount() { - y = m.LineCount() - 1 + if y >= buf.LineCount() { + y = buf.LineCount() - 1 } - m.SetCursorY(y) - m.ClampCursorX() + win.SetCursorLine(y) } } - m.SetCursorY(initY) - m.ClampCursorX() + win.SetCursorLine(initY) return nil } diff --git a/internal/action/insert.go b/internal/action/insert.go index 50d48ed..5181860 100644 --- a/internal/action/insert.go +++ b/internal/action/insert.go @@ -28,8 +28,8 @@ type EnterInsertAfter struct { } func (a EnterInsertAfter) Execute(m Model) tea.Cmd { - m.SetCursorX(m.CursorX() + 1) - m.ClampCursorX() + win := m.ActiveWindow() + win.SetCursorCol(win.Cursor.Col + 1) // Start recording m.SetInsertRecording(a.Count, a) @@ -47,8 +47,8 @@ type EnterInsertLineStart struct { } func (a EnterInsertLineStart) Execute(m Model) tea.Cmd { - m.SetCursorX(0) - m.ClampCursorX() + win := m.ActiveWindow() + win.SetCursorCol(0) // Start recording m.SetInsertRecording(a.Count, a) @@ -66,8 +66,9 @@ type EnterInsertLineEnd struct { } func (a EnterInsertLineEnd) Execute(m Model) tea.Cmd { - m.SetCursorX(len(m.Line(m.CursorY()))) - m.ClampCursorX() + win := m.ActiveWindow() + buf := m.ActiveBuffer() + win.SetCursorCol(len(buf.Lines[win.Cursor.Line])) // Start recording m.SetInsertRecording(a.Count, a) @@ -85,16 +86,18 @@ type OpenLineBelow struct { } func (a OpenLineBelow) Execute(m Model) tea.Cmd { - pos := m.CursorY() + win := m.ActiveWindow() + buf := m.ActiveBuffer() - if pos >= m.LineCount() { - m.InsertLine(m.LineCount(), "") + pos := win.Cursor.Line + + if pos >= buf.LineCount() { + buf.InsertLine(buf.LineCount(), "") } else { - m.InsertLine(pos+1, "") + buf.InsertLine(pos+1, "") } - m.SetCursorY(m.CursorY() + 1) - m.SetCursorX(0) + win.SetCursorPos(win.Cursor.Line+1, 0) // Start recording m.SetInsertRecording(a.Count, a) @@ -112,9 +115,12 @@ type OpenLineAbove struct { } func (a OpenLineAbove) Execute(m Model) tea.Cmd { - pos := m.CursorY() - m.InsertLine(pos, "") - m.SetCursorX(0) + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + pos := win.Cursor.Line + buf.InsertLine(pos, "") + win.SetCursorCol(0) // Start recording m.SetInsertRecording(a.Count, a) @@ -134,14 +140,17 @@ type InsertChar struct { } func (a InsertChar) Execute(m Model) tea.Cmd { - x, y := m.CursorX(), m.CursorY() - l := m.Line(y) + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + x, y := win.Cursor.Col, win.Cursor.Line + l := buf.Lines[y] if x < len(l) { - m.SetLine(y, l[:x]+a.Char+l[x:]) + buf.SetLine(y, l[:x]+a.Char+l[x:]) } else { - m.SetLine(y, l+a.Char) + buf.SetLine(y, l+a.Char) } - m.SetCursorX(x + len(a.Char)) + win.SetCursorCol(x + len(a.Char)) return nil } @@ -149,16 +158,18 @@ func (a InsertChar) Execute(m Model) tea.Cmd { type InsertNewline struct{} func (a InsertNewline) Execute(m Model) tea.Cmd { - x, y := m.CursorX(), m.CursorY() - l := m.Line(y) + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + x, y := win.Cursor.Col, win.Cursor.Line + l := buf.Lines[y] if x == len(l) { - m.InsertLine(y+1, "") + buf.InsertLine(y+1, "") } else { - m.SetLine(y, l[:x]) - m.InsertLine(y+1, l[x:]) + buf.SetLine(y, l[:x]) + buf.InsertLine(y+1, l[x:]) } - m.SetCursorY(y + 1) - m.SetCursorX(0) + win.SetCursorPos(y+1, 0) return nil } @@ -166,18 +177,20 @@ func (a InsertNewline) Execute(m Model) tea.Cmd { type InsertBackspace struct{} func (a InsertBackspace) Execute(m Model) tea.Cmd { - x, y := m.CursorX(), m.CursorY() - l := m.Line(y) + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + x, y := win.Cursor.Col, win.Cursor.Line + l := buf.Lines[y] if x > 0 { - m.SetLine(y, l[:x-1]+l[x:]) - m.SetCursorX(x - 1) + buf.SetLine(y, l[:x-1]+l[x:]) + win.SetCursorCol(x - 1) } else if y > 0 { - prevLine := m.Line(y - 1) + prevLine := buf.Lines[y-1] newX := len(prevLine) - m.SetLine(y-1, prevLine+l) - m.DeleteLine(y) - m.SetCursorY(y - 1) - m.SetCursorX(newX) + buf.SetLine(y-1, prevLine+l) + buf.DeleteLine(y) + win.SetCursorPos(y-1, newX) } return nil } @@ -186,14 +199,17 @@ func (a InsertBackspace) Execute(m Model) tea.Cmd { type InsertDelete struct{} func (a InsertDelete) Execute(m Model) tea.Cmd { - x, y := m.CursorX(), m.CursorY() - l := m.Line(y) - if x == len(l) && y < m.LineCount()-1 { - nextLine := m.Line(y + 1) - m.SetLine(y, l+nextLine) - m.DeleteLine(y + 1) + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + x, y := win.Cursor.Col, win.Cursor.Line + l := buf.Lines[y] + if x == len(l) && y < buf.LineCount()-1 { + nextLine := buf.Lines[y+1] + buf.SetLine(y, l+nextLine) + buf.DeleteLine(y + 1) } else if x < len(l) { - m.SetLine(y, l[:x]+l[x+1:]) + buf.SetLine(y, l[:x]+l[x+1:]) } return nil } @@ -202,15 +218,18 @@ func (a InsertDelete) Execute(m Model) tea.Cmd { type InsertTab struct{} func (a InsertTab) Execute(m Model) tea.Cmd { - x, y := m.CursorX(), m.CursorY() - l := m.Line(y) + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + x, y := win.Cursor.Col, win.Cursor.Line + l := buf.Lines[y] tabs := strings.Repeat(" ", m.Settings().TabSize) if x < len(l) { - m.SetLine(y, l[:x]+tabs+l[x:]) + buf.SetLine(y, l[:x]+tabs+l[x:]) } else { - m.SetLine(y, l+tabs) + buf.SetLine(y, l+tabs) } - m.SetCursorX(x + len(tabs)) + win.SetCursorCol(x + len(tabs)) return nil } @@ -229,18 +248,20 @@ func isPunctuation(c byte) bool { } func (a InsertDeletePreviousWord) Execute(m Model) tea.Cmd { - x, y := m.CursorX(), m.CursorY() - line := m.Line(y) + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + x, y := win.Cursor.Col, win.Cursor.Line + line := buf.Lines[y] // At start of line: merge with previous line (same as backspace) if x == 0 { if y > 0 { - prevLine := m.Line(y - 1) + prevLine := buf.Lines[y-1] newX := len(prevLine) - m.SetLine(y-1, prevLine+line) - m.DeleteLine(y) - m.SetCursorY(y - 1) - m.SetCursorX(newX) + buf.SetLine(y-1, prevLine+line) + buf.DeleteLine(y) + win.SetCursorPos(y-1, newX) } return nil } @@ -254,8 +275,8 @@ func (a InsertDeletePreviousWord) Execute(m Model) tea.Cmd { newX-- } - m.SetLine(y, line[:newX]+line[x:]) - m.SetCursorX(newX) + buf.SetLine(y, line[:newX]+line[x:]) + win.SetCursorCol(newX) return nil } @@ -271,8 +292,8 @@ func (a InsertDeletePreviousWord) Execute(m Model) tea.Cmd { } // Delete everything from newX up to x in one operation - m.SetLine(y, line[:newX]+line[x:]) - m.SetCursorX(newX) + buf.SetLine(y, line[:newX]+line[x:]) + win.SetCursorCol(newX) return nil } diff --git a/internal/action/misc.go b/internal/action/misc.go index 414fae5..63160ee 100644 --- a/internal/action/misc.go +++ b/internal/action/misc.go @@ -25,8 +25,9 @@ func (a EnterComandMode) Execute(m Model) tea.Cmd { type EnterVisualMode struct{} func (a EnterVisualMode) Execute(m Model) tea.Cmd { - m.SetAnchorX(m.CursorX()) - m.SetAnchorY(m.CursorY()) + win := m.ActiveWindow() + win.SetAnchorCol(win.Cursor.Col) + win.SetAnchorLine(win.Cursor.Line) m.SetMode(VisualMode) return nil } @@ -35,8 +36,9 @@ func (a EnterVisualMode) Execute(m Model) tea.Cmd { type EnterVisualLineMode struct{} func (a EnterVisualLineMode) Execute(m Model) tea.Cmd { - m.SetAnchorX(m.CursorX()) - m.SetAnchorY(m.CursorY()) + win := m.ActiveWindow() + win.SetAnchorCol(win.Cursor.Col) + win.SetAnchorLine(win.Cursor.Line) m.SetMode(VisualLineMode) return nil } @@ -45,8 +47,9 @@ func (a EnterVisualLineMode) Execute(m Model) tea.Cmd { type EnterVisualBlockMode struct{} func (a EnterVisualBlockMode) Execute(m Model) tea.Cmd { - m.SetAnchorX(m.CursorX()) - m.SetAnchorY(m.CursorY()) + win := m.ActiveWindow() + win.SetAnchorCol(win.Cursor.Col) + win.SetAnchorLine(win.Cursor.Line) m.SetMode(VisualBlockMode) return nil } diff --git a/internal/action/paste.go b/internal/action/paste.go index 67e4b95..542d635 100644 --- a/internal/action/paste.go +++ b/internal/action/paste.go @@ -13,6 +13,9 @@ type Paste struct { } func (a Paste) Execute(m Model) tea.Cmd { + win := m.ActiveWindow() + buf := m.ActiveBuffer() + // Get reg reg, found := m.GetRegister('"') if !found { @@ -28,20 +31,20 @@ func (a Paste) Execute(m Model) tea.Cmd { switch reg.Type { case LinewiseRegister: { - initY := m.CursorY() + initY := win.Cursor.Line lines := reg.Content insertPos := initY + 1 // Run count times for range a.Count { for _, line := range lines { - m.InsertLine(insertPos, line) + buf.InsertLine(insertPos, line) insertPos++ } } - if m.LineCount() > 1 { - m.SetCursorY(initY + 1) + if buf.LineCount() > 1 { + win.SetCursorLine(initY + 1) } } case CharwiseRegister: @@ -54,19 +57,18 @@ func (a Paste) Execute(m Model) tea.Cmd { break } - x := m.CursorX() - y := m.CursorY() + x := win.Cursor.Col + y := win.Cursor.Line cnt := strings.Repeat(lines[0], max(1, a.Count)) - curLine := m.Line(y) + curLine := buf.Lines[y] // Catch edge cases, end of line, start of blank line insertAt := min(x+1, len(curLine)) newLine := curLine[:insertAt] + cnt + curLine[insertAt:] - m.SetLine(y, newLine) + buf.SetLine(y, newLine) - m.SetCursorX(x + len(cnt)) - m.ClampCursorX() + win.SetCursorCol(x + len(cnt)) } default: m.SetCommandError(fmt.Errorf("Register type is not implemented.")) @@ -88,6 +90,9 @@ type PasteBefore struct { } func (a PasteBefore) Execute(m Model) tea.Cmd { + win := m.ActiveWindow() + buf := m.ActiveBuffer() + // Get reg reg, found := m.GetRegister('"') if !found { @@ -98,14 +103,14 @@ func (a PasteBefore) Execute(m Model) tea.Cmd { switch reg.Type { case LinewiseRegister: { - initY := m.CursorY() + initY := win.Cursor.Line lines := reg.Content insertPos := initY // Leave here, this will effectively move the lines below // Run count times for range a.Count { for _, line := range lines { - m.InsertLine(insertPos, line) + buf.InsertLine(insertPos, line) insertPos++ } } @@ -120,19 +125,18 @@ func (a PasteBefore) Execute(m Model) tea.Cmd { break } - x := m.CursorX() - y := m.CursorY() + x := win.Cursor.Col + y := win.Cursor.Line cnt := strings.Repeat(lines[0], max(1, a.Count)) - curLine := m.Line(y) + curLine := buf.Lines[y] // Catch edge cases, end of line, start of blank line insertAt := min(x, len(curLine)) newLine := curLine[:insertAt] + cnt + curLine[insertAt:] - m.SetLine(y, newLine) + buf.SetLine(y, newLine) - m.SetCursorX(x + len(cnt)) - m.ClampCursorX() + win.SetCursorCol(x + len(cnt)) } default: m.SetCommandError(fmt.Errorf("Register type is not implemented.")) @@ -183,11 +187,10 @@ func (a VisualPaste) Execute(m Model) tea.Cmd { // normalizeSelection returns start and end positions with start always before end func normalizeSelection(m Model) (Position, Position) { - anchorX, anchorY := m.AnchorX(), m.AnchorY() - cursorX, cursorY := m.CursorX(), m.CursorY() + win := m.ActiveWindow() - start := Position{Line: anchorY, Col: anchorX} - end := Position{Line: cursorY, Col: cursorX} + start := Position{Line: win.Anchor.Line, Col: win.Anchor.Col} + end := Position{Line: win.Cursor.Line, Col: win.Cursor.Col} // Normalize so start is always before end if start.Line > end.Line || (start.Line == end.Line && start.Col > end.Col) { @@ -199,6 +202,9 @@ func normalizeSelection(m Model) (Position, Position) { // visualCharPaste handles paste in visual (character) mode func visualCharPaste(m Model, reg Register, start, end Position) { + win := m.ActiveWindow() + buf := m.ActiveBuffer() + // First, extract the text that will be deleted (to save to register) deletedText := extractCharSelection(m, start, end) @@ -211,14 +217,14 @@ func visualCharPaste(m Model, reg Register, start, end Position) { } else if reg.Type == CharwiseRegister { // Charwise paste: insert text at cursor position if len(reg.Content) == 1 { - line := m.Line(start.Line) + line := buf.Lines[start.Line] insertAt := min(start.Col, len(line)) newLine := line[:insertAt] + reg.Content[0] + line[insertAt:] - m.SetLine(start.Line, newLine) + buf.SetLine(start.Line, newLine) // Cursor at end of pasted text - m.SetCursorX(insertAt + len(reg.Content[0]) - 1) - m.SetCursorY(start.Line) + win.SetCursorCol(insertAt + len(reg.Content[0]) - 1) + win.SetCursorLine(start.Line) } } else if reg.Type == LinewiseRegister { // Linewise paste in visual char mode: replace selection with lines @@ -226,38 +232,39 @@ func visualCharPaste(m Model, reg Register, start, end Position) { for i, content := range reg.Content { if i == 0 { // First line: insert at start position - line := m.Line(start.Line) + line := buf.Lines[start.Line] insertAt := min(start.Col, len(line)) newLine := line[:insertAt] + content if len(reg.Content) == 1 { // Single line register - append rest of line newLine += line[insertAt:] } - m.SetLine(start.Line, newLine) + buf.SetLine(start.Line, newLine) } else { // Subsequent lines: insert new lines - m.InsertLine(start.Line+i, content) + buf.InsertLine(start.Line+i, content) } } - m.SetCursorY(start.Line) - m.SetCursorX(start.Col) + win.SetCursorLine(start.Line) + win.SetCursorCol(start.Col) } - m.ClampCursorX() - // Update register with deleted text m.UpdateDefaultRegister(CharwiseRegister, []string{deletedText}) } // visualBlockPaste handles paste in visual block mode func visualBlockPaste(m Model, reg Register, start, end Position) { + win := m.ActiveWindow() + buf := m.ActiveBuffer() + startCol := min(start.Col, end.Col) endCol := max(start.Col, end.Col) // Extract deleted text (for register) var deletedLines []string for y := start.Line; y <= end.Line; y++ { - line := m.Line(y) + line := buf.Lines[y] if startCol < len(line) { ec := min(endCol+1, len(line)) deletedLines = append(deletedLines, line[startCol:ec]) @@ -268,12 +275,12 @@ func visualBlockPaste(m Model, reg Register, start, end Position) { // Delete the block selection for y := start.Line; y <= end.Line; y++ { - line := m.Line(y) + line := buf.Lines[y] if startCol >= len(line) { continue } ec := min(endCol+1, len(line)) - m.SetLine(y, line[:startCol]+line[ec:]) + buf.SetLine(y, line[:startCol]+line[ec:]) } // Insert register content @@ -284,20 +291,19 @@ func visualBlockPaste(m Model, reg Register, start, end Position) { } for y := start.Line; y <= end.Line; y++ { - line := m.Line(y) + line := buf.Lines[y] insertAt := min(startCol, len(line)) // Pad with spaces if needed for len(line) < insertAt { line += " " } newLine := line[:insertAt] + pasteContent + line[insertAt:] - m.SetLine(y, newLine) + buf.SetLine(y, newLine) } } - m.SetCursorY(start.Line) - m.SetCursorX(startCol) - m.ClampCursorX() + win.SetCursorLine(start.Line) + win.SetCursorCol(startCol) // Update register with deleted block text (joined) m.UpdateDefaultRegister(CharwiseRegister, []string{strings.Join(deletedLines, "\n")}) @@ -305,48 +311,50 @@ func visualBlockPaste(m Model, reg Register, start, end Position) { // visualLinePaste handles paste in visual line mode func visualLinePaste(m Model, reg Register, start, end Position) { + win := m.ActiveWindow() + buf := m.ActiveBuffer() + // Extract deleted lines (for register) var deletedLines []string for y := start.Line; y <= end.Line; y++ { - deletedLines = append(deletedLines, m.Line(y)) + deletedLines = append(deletedLines, buf.Lines[y]) } // Delete the selected lines (from end to start to preserve indices) for y := end.Line; y >= start.Line; y-- { - m.DeleteLine(y) + buf.DeleteLine(y) } // Insert register content if len(reg.Content) == 0 { // Empty register - ensure at least one empty line exists - if m.LineCount() == 0 { - m.InsertLine(0, "") + if buf.LineCount() == 0 { + buf.InsertLine(0, "") } } else if reg.Type == LinewiseRegister { // Linewise register: insert each line insertPos := start.Line for _, content := range reg.Content { - m.InsertLine(insertPos, content) + buf.InsertLine(insertPos, content) insertPos++ } } else { // Charwise register: insert as a single line - m.InsertLine(start.Line, reg.Content[0]) + buf.InsertLine(start.Line, reg.Content[0]) } // Ensure we have at least one line - if m.LineCount() == 0 { - m.InsertLine(0, "") + if buf.LineCount() == 0 { + buf.InsertLine(0, "") } // Position cursor at start of pasted content y := start.Line - if y >= m.LineCount() { - y = m.LineCount() - 1 + if y >= buf.LineCount() { + y = buf.LineCount() - 1 } - m.SetCursorY(y) - m.SetCursorX(0) - m.ClampCursorX() + win.SetCursorLine(y) + win.SetCursorCol(0) // Update register with deleted lines m.UpdateDefaultRegister(LinewiseRegister, deletedLines) @@ -354,8 +362,10 @@ func visualLinePaste(m Model, reg Register, start, end Position) { // extractCharSelection extracts text from a character selection func extractCharSelection(m Model, start, end Position) string { + buf := m.ActiveBuffer() + if start.Line == end.Line { - line := m.Line(start.Line) + line := buf.Lines[start.Line] endCol := min(end.Col+1, len(line)) startCol := min(start.Col, len(line)) if startCol >= endCol { @@ -368,7 +378,7 @@ func extractCharSelection(m Model, start, end Position) string { var result strings.Builder // First line: from start.Col to end - firstLine := m.Line(start.Line) + firstLine := buf.Lines[start.Line] if start.Col < len(firstLine) { result.WriteString(firstLine[start.Col:]) } @@ -376,12 +386,12 @@ func extractCharSelection(m Model, start, end Position) string { // Middle lines: entire lines for y := start.Line + 1; y < end.Line; y++ { - result.WriteString(m.Line(y)) + result.WriteString(buf.Lines[y]) result.WriteString("\n") } // Last line: from beginning to end.Col - lastLine := m.Line(end.Line) + lastLine := buf.Lines[end.Line] endCol := min(end.Col+1, len(lastLine)) result.WriteString(lastLine[:endCol]) @@ -390,13 +400,16 @@ func extractCharSelection(m Model, start, end Position) string { // deleteCharSelectionForPaste deletes a character selection (similar to operator/delete.go) func deleteCharSelectionForPaste(m Model, start, end Position) { + win := m.ActiveWindow() + buf := m.ActiveBuffer() + if start.Line == end.Line { - line := m.Line(start.Line) + line := buf.Lines[start.Line] endCol := min(end.Col+1, len(line)) - m.SetLine(start.Line, line[:start.Col]+line[endCol:]) + buf.SetLine(start.Line, line[:start.Col]+line[endCol:]) } else { - startLine := m.Line(start.Line) - endLine := m.Line(end.Line) + startLine := buf.Lines[start.Line] + endLine := buf.Lines[end.Line] prefix := "" if start.Col < len(startLine) { @@ -410,13 +423,13 @@ func deleteCharSelectionForPaste(m Model, start, end Position) { // Delete from end back to start to preserve indices for i := end.Line; i >= start.Line; i-- { - m.DeleteLine(i) + buf.DeleteLine(i) } - m.InsertLine(start.Line, prefix+suffix) + buf.InsertLine(start.Line, prefix+suffix) } - m.SetCursorY(start.Line) - m.SetCursorX(start.Col) + win.SetCursorLine(start.Line) + win.SetCursorCol(start.Col) } // Ensure VisualPaste implements Repeatable diff --git a/internal/action/window.go b/internal/action/window.go index a003949..553cdaa 100644 --- a/internal/action/window.go +++ b/internal/action/window.go @@ -80,6 +80,13 @@ func (w *Window) AdjustScroll() { w.ScrollY = max(0, min(w.ScrollY, maxScroll)) } +// ================================================== +// View methods +// ================================================== +func (w *Window) View() { + +} + // ================================================== // Setters // ================================================== diff --git a/internal/editor/helpers_example_test.go b/internal/editor/helpers_example_test.go index 38bd62b..e8f0f90 100644 --- a/internal/editor/helpers_example_test.go +++ b/internal/editor/helpers_example_test.go @@ -19,8 +19,9 @@ func TestHelperExamples(t *testing.T) { WithLines([]string{"hello", "world"}), ) m := getFinalModel(t, tm) - if len(m.Lines()) != 2 { - t.Errorf("expected 2 lines, got %d", len(m.Lines())) + buf := m.ActiveBuffer() + if buf.LineCount() != 2 { + t.Errorf("expected 2 lines, got %d", buf.LineCount()) } }) @@ -29,8 +30,9 @@ func TestHelperExamples(t *testing.T) { WithCursorPos(action.Position{Line: 2, Col: 3}), ) m := getFinalModel(t, tm) - if m.CursorY() != 2 || m.CursorX() != 3 { - t.Errorf("expected cursor at (2,3), got (%d,%d)", m.CursorY(), m.CursorX()) + win := m.ActiveWindow() + if win.Cursor.Line != 2 || win.Cursor.Col != 3 { + t.Errorf("expected cursor at (2,3), got (%d,%d)", win.Cursor.Line, win.Cursor.Col) } }) @@ -39,8 +41,9 @@ func TestHelperExamples(t *testing.T) { WithTermSize(120, 40), ) m := getFinalModel(t, tm) - if m.WinW() != 120 || m.WinH() != 40 { - t.Errorf("expected size 120x40, got %dx%d", m.WinW(), m.WinH()) + win := m.ActiveWindow() + if win.Width != 120 || win.Height != 40 { + t.Errorf("expected size 120x40, got %dx%d", win.Width, win.Height) } }) @@ -73,14 +76,17 @@ func TestHelperExamples(t *testing.T) { m := getFinalModel(t, tm) // Verify all options were applied - if len(m.Lines()) != 3 { - t.Errorf("expected 3 lines, got %d", len(m.Lines())) + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + if buf.LineCount() != 3 { + t.Errorf("expected 3 lines, got %d", buf.LineCount()) } - if m.CursorY() != 1 || m.CursorX() != 5 { - t.Errorf("expected cursor at (1,5), got (%d,%d)", m.CursorY(), m.CursorX()) + if win.Cursor.Line != 1 || win.Cursor.Col != 5 { + t.Errorf("expected cursor at (1,5), got (%d,%d)", win.Cursor.Line, win.Cursor.Col) } - if m.WinW() != 100 || m.WinH() != 30 { - t.Errorf("expected size 100x30, got %dx%d", m.WinW(), m.WinH()) + if win.Width != 100 || win.Height != 30 { + t.Errorf("expected size 100x30, got %dx%d", win.Width, win.Height) } reg, ok := m.GetRegister('"') @@ -93,25 +99,29 @@ func TestHelperExamples(t *testing.T) { // Old style helpers still work for existing tests tm1 := newTestModelWithLines(t, []string{"a", "b"}) m1 := getFinalModel(t, tm1) - if len(m1.Lines()) != 2 { + buf1 := m1.ActiveBuffer() + if buf1.LineCount() != 2 { t.Error("newTestModelWithLines failed") } tm2 := newTestModelWithCursorPos(t, action.Position{Line: 1, Col: 2}) m2 := getFinalModel(t, tm2) - if m2.CursorY() != 1 { + win2 := m2.ActiveWindow() + if win2.Cursor.Line != 1 { t.Error("newTestModelWithCursorPos failed") } tm3 := newTestModelWithLinesAndCursorPos(t, []string{"x"}, action.Position{Line: 0, Col: 0}) m3 := getFinalModel(t, tm3) - if len(m3.Lines()) != 1 { + buf3 := m3.ActiveBuffer() + if buf3.LineCount() != 1 { t.Error("newTestModelWithLinesAndCursorPos failed") } tm4 := newTestModelWithTermSize(t, []string{"y"}, action.Position{Line: 0, Col: 0}, 50, 20) m4 := getFinalModel(t, tm4) - if m4.WinW() != 50 { + win4 := m4.ActiveWindow() + if win4.Width != 50 { t.Error("newTestModelWithTermSize failed") } }) diff --git a/internal/editor/helpers_test.go b/internal/editor/helpers_test.go index 1f3b496..0ac1dfc 100644 --- a/internal/editor/helpers_test.go +++ b/internal/editor/helpers_test.go @@ -9,6 +9,8 @@ import ( "github.com/charmbracelet/x/exp/teatest" ) +// NOTE: Lots of this actually sucks ass, but it works for now... + // sendKeys sends a sequence of keys to the test model func sendKeys(tm *teatest.TestModel, keys ...string) { for _, key := range keys { @@ -94,12 +96,31 @@ func newTestModel(t *testing.T, opts ...TestModelOption) *teatest.TestModel { opt(&cfg) } - // Create model - m := NewModel(cfg.lines, cfg.pos) + buf := action.NewBufferBuilder(). + WithLines(cfg.lines). + Build() - // Set register if provided + win := action.NewWindowBuilder(). + WithBuffer(&buf). + WithCursorPos(cfg.pos.Line, cfg.pos.Col). + WithDimensions(cfg.width, cfg.height). + Build() + + // Create model with default registers + m := NewModelBuilder(). + AddBuffer(&buf). + AddWindow(&win). + WithActiveWindowId(win.Id). + WithTermSize(cfg.width, cfg.height). + Build() + + // Set register if provided (must be done AFTER Build because SetRegister + // requires the register to already exist in the default register map) if cfg.regContent != nil { - m.SetRegister(cfg.regName, cfg.regType, cfg.regContent) + err := m.SetRegister(cfg.regName, cfg.regType, cfg.regContent) + if err != nil { + t.Fatalf("Failed to set register %c: %v", cfg.regName, err) + } } return teatest.NewTestModel(t, m, teatest.WithInitialTermSize(cfg.width, cfg.height)) diff --git a/internal/editor/integration_delete_test.go b/internal/editor/integration_delete_test.go index bf3feac..eb121ad 100644 --- a/internal/editor/integration_delete_test.go +++ b/internal/editor/integration_delete_test.go @@ -13,8 +13,8 @@ func TestDeleteChar(t *testing.T) { sendKeys(tm, "x") m := getFinalModel(t, tm) - if m.Line(0) != "ello" { - t.Errorf("lines[0] = %q, want 'ello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "ello" { + t.Errorf("lines[0] = %q, want 'ello'", m.ActiveBuffer().Lines[0]) } }) @@ -24,8 +24,8 @@ func TestDeleteChar(t *testing.T) { sendKeys(tm, "x") m := getFinalModel(t, tm) - if m.Line(0) != "helo" { - t.Errorf("lines[0] = %q, want 'helo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "helo" { + t.Errorf("lines[0] = %q, want 'helo'", m.ActiveBuffer().Lines[0]) } }) @@ -35,8 +35,8 @@ func TestDeleteChar(t *testing.T) { sendKeys(tm, "x") m := getFinalModel(t, tm) - if m.Line(0) != "hell" { - t.Errorf("lines[0] = %q, want 'hell'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hell" { + t.Errorf("lines[0] = %q, want 'hell'", m.ActiveBuffer().Lines[0]) } }) @@ -46,8 +46,8 @@ func TestDeleteChar(t *testing.T) { sendKeys(tm, "x", "x") m := getFinalModel(t, tm) - if m.Line(0) != "llo" { - t.Errorf("lines[0] = %q, want 'llo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "llo" { + t.Errorf("lines[0] = %q, want 'llo'", m.ActiveBuffer().Lines[0]) } }) } @@ -59,8 +59,8 @@ func TestDeleteCharWithCount(t *testing.T) { sendKeys(tm, "3", "x") m := getFinalModel(t, tm) - if m.Line(0) != "lo" { - t.Errorf("lines[0] = %q, want 'lo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "lo" { + t.Errorf("lines[0] = %q, want 'lo'", m.ActiveBuffer().Lines[0]) } }) @@ -70,8 +70,8 @@ func TestDeleteCharWithCount(t *testing.T) { sendKeys(tm, "1", "0", "x") m := getFinalModel(t, tm) - if m.Line(0) != "" { - t.Errorf("lines[0] = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("lines[0] = %q, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -81,8 +81,8 @@ func TestDeleteCharWithCount(t *testing.T) { sendKeys(tm, "2", "x") m := getFinalModel(t, tm) - if m.Line(0) != "hlo" { - t.Errorf("lines[0] = %q, want 'hlo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hlo" { + t.Errorf("lines[0] = %q, want 'hlo'", m.ActiveBuffer().Lines[0]) } }) } @@ -94,11 +94,11 @@ func TestDeleteCharEdgeCases(t *testing.T) { sendKeys(tm, "x") m := getFinalModel(t, tm) - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -108,8 +108,8 @@ func TestDeleteCharEdgeCases(t *testing.T) { sendKeys(tm, "x") m := getFinalModel(t, tm) - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -119,8 +119,8 @@ func TestDeleteCharEdgeCases(t *testing.T) { sendKeys(tm, "x") m := getFinalModel(t, tm) - if m.Line(0) != "a" { - t.Errorf("Line(0) = %q, want 'a'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "a" { + t.Errorf("Line(0) = %q, want 'a'", m.ActiveBuffer().Lines[0]) } }) @@ -130,8 +130,8 @@ func TestDeleteCharEdgeCases(t *testing.T) { sendKeys(tm, "x") m := getFinalModel(t, tm) - if m.Line(0) != "ab c" { - t.Errorf("Line(0) = %q, want 'ab c'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "ab c" { + t.Errorf("Line(0) = %q, want 'ab c'", m.ActiveBuffer().Lines[0]) } }) @@ -141,11 +141,11 @@ func TestDeleteCharEdgeCases(t *testing.T) { sendKeys(tm, "x") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(1) != "world" { - t.Errorf("Line(1) = %q, want 'world'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "world" { + t.Errorf("Line(1) = %q, want 'world'", m.ActiveBuffer().Lines[1]) } }) @@ -155,8 +155,8 @@ func TestDeleteCharEdgeCases(t *testing.T) { sendKeys(tm, "x", "x", "x") m := getFinalModel(t, tm) - if m.Line(0) != "lo" { - t.Errorf("Line(0) = %q, want 'lo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "lo" { + t.Errorf("Line(0) = %q, want 'lo'", m.ActiveBuffer().Lines[0]) } }) @@ -166,8 +166,8 @@ func TestDeleteCharEdgeCases(t *testing.T) { sendKeys(tm, "x") m := getFinalModel(t, tm) - if m.Line(0) != "ab" { - t.Errorf("Line(0) = %q, want 'ab'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "ab" { + t.Errorf("Line(0) = %q, want 'ab'", m.ActiveBuffer().Lines[0]) } }) @@ -177,8 +177,8 @@ func TestDeleteCharEdgeCases(t *testing.T) { sendKeys(tm, "5", "x") m := getFinalModel(t, tm) - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -188,8 +188,8 @@ func TestDeleteCharEdgeCases(t *testing.T) { sendKeys(tm, "x") m := getFinalModel(t, tm) - if m.Line(0) != "abde" { - t.Errorf("Line(0) = %q, want 'abde'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "abde" { + t.Errorf("Line(0) = %q, want 'abde'", m.ActiveBuffer().Lines[0]) } }) } @@ -201,8 +201,8 @@ func TestDeleteToEndOfLine(t *testing.T) { sendKeys(tm, "D") m := getFinalModel(t, tm) - if m.Line(0) != "hello" { - t.Errorf("Line(0) = %q, want 'hello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello" { + t.Errorf("Line(0) = %q, want 'hello'", m.ActiveBuffer().Lines[0]) } }) @@ -212,8 +212,8 @@ func TestDeleteToEndOfLine(t *testing.T) { sendKeys(tm, "D") m := getFinalModel(t, tm) - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -223,8 +223,8 @@ func TestDeleteToEndOfLine(t *testing.T) { sendKeys(tm, "D") m := getFinalModel(t, tm) - if m.Line(0) != "hell" { - t.Errorf("Line(0) = %q, want 'hell'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hell" { + t.Errorf("Line(0) = %q, want 'hell'", m.ActiveBuffer().Lines[0]) } }) @@ -235,8 +235,8 @@ func TestDeleteToEndOfLine(t *testing.T) { m := getFinalModel(t, tm) // Cursor should move to last character of remaining text - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -246,8 +246,8 @@ func TestDeleteToEndOfLine(t *testing.T) { sendKeys(tm, "D") m := getFinalModel(t, tm) - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -257,14 +257,14 @@ func TestDeleteToEndOfLine(t *testing.T) { sendKeys(tm, "2", "D") m := getFinalModel(t, tm) - if m.LineCount() != 3 { - t.Errorf("LineCount() = %q, want '3'", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %q, want '3'", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "he" { - t.Errorf("Line(0) = %q, want 'he'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "he" { + t.Errorf("Line(0) = %q, want 'he'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "hi" { - t.Errorf("Line(1) = %q, want 'hi'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "hi" { + t.Errorf("Line(1) = %q, want 'hi'", m.ActiveBuffer().Lines[1]) } }) @@ -274,11 +274,11 @@ func TestDeleteToEndOfLine(t *testing.T) { sendKeys(tm, "8", "D") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %q, want '1'", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %q, want '1'", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "he" { - t.Errorf("Line(0) = %q, want 'he'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "he" { + t.Errorf("Line(0) = %q, want 'he'", m.ActiveBuffer().Lines[0]) } }) } @@ -290,8 +290,8 @@ func TestDeleteToEndOfLineEdgeCases(t *testing.T) { sendKeys(tm, "D") m := getFinalModel(t, tm) - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -301,11 +301,11 @@ func TestDeleteToEndOfLineEdgeCases(t *testing.T) { sendKeys(tm, "D") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(1) != "" { - t.Errorf("Line(1) = %q, want ''", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "" { + t.Errorf("Line(1) = %q, want ''", m.ActiveBuffer().Lines[1]) } }) @@ -315,11 +315,11 @@ func TestDeleteToEndOfLineEdgeCases(t *testing.T) { sendKeys(tm, "D") m := getFinalModel(t, tm) - if m.Line(0) != "line 1" { - t.Errorf("Line(0) = %q, want 'line 1'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 1" { + t.Errorf("Line(0) = %q, want 'line 1'", m.ActiveBuffer().Lines[0]) } - if m.Line(2) != "line 3" { - t.Errorf("Line(2) = %q, want 'line 3'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "line 3" { + t.Errorf("Line(2) = %q, want 'line 3'", m.ActiveBuffer().Lines[2]) } }) @@ -329,12 +329,12 @@ func TestDeleteToEndOfLineEdgeCases(t *testing.T) { sendKeys(tm, "D") m := getFinalModel(t, tm) - if m.Line(0) != "he" { - t.Errorf("Line(0) = %q, want 'he'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "he" { + t.Errorf("Line(0) = %q, want 'he'", m.ActiveBuffer().Lines[0]) } // Cursor should clamp to last char - if m.CursorX() != 1 { - t.Errorf("CursorX() = %d, want 1", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 1 { + t.Errorf("CursorX() = %d, want 1", m.ActiveWindow().Cursor.Col) } }) @@ -344,8 +344,8 @@ func TestDeleteToEndOfLineEdgeCases(t *testing.T) { sendKeys(tm, "D") m := getFinalModel(t, tm) - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -355,8 +355,8 @@ func TestDeleteToEndOfLineEdgeCases(t *testing.T) { sendKeys(tm, "D") m := getFinalModel(t, tm) - if m.Line(0) != " " { - t.Errorf("Line(0) = %q, want ' '", m.Line(0)) + if m.ActiveBuffer().Lines[0] != " " { + t.Errorf("Line(0) = %q, want ' '", m.ActiveBuffer().Lines[0]) } }) @@ -366,8 +366,8 @@ func TestDeleteToEndOfLineEdgeCases(t *testing.T) { sendKeys(tm, "D") m := getFinalModel(t, tm) - if m.Line(0) != "hello" { - t.Errorf("Line(0) = %q, want 'hello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello" { + t.Errorf("Line(0) = %q, want 'hello'", m.ActiveBuffer().Lines[0]) } }) @@ -377,8 +377,8 @@ func TestDeleteToEndOfLineEdgeCases(t *testing.T) { sendKeys(tm, "D") m := getFinalModel(t, tm) - if m.Line(0) != "a" { - t.Errorf("Line(0) = %q, want 'a'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "a" { + t.Errorf("Line(0) = %q, want 'a'", m.ActiveBuffer().Lines[0]) } }) @@ -388,8 +388,8 @@ func TestDeleteToEndOfLineEdgeCases(t *testing.T) { sendKeys(tm, "D") m := getFinalModel(t, tm) - if m.Line(1) != "world" { - t.Errorf("Line(1) = %q, want 'world'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "world" { + t.Errorf("Line(1) = %q, want 'world'", m.ActiveBuffer().Lines[1]) } }) @@ -399,11 +399,11 @@ func TestDeleteToEndOfLineEdgeCases(t *testing.T) { sendKeys(tm, "D") m := getFinalModel(t, tm) - if m.Line(0) != "first" { - t.Errorf("Line(0) = %q, want 'first'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "first" { + t.Errorf("Line(0) = %q, want 'first'", m.ActiveBuffer().Lines[0]) } - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } }) @@ -413,8 +413,8 @@ func TestDeleteToEndOfLineEdgeCases(t *testing.T) { sendKeys(tm, "D") m := getFinalModel(t, tm) - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want 1", m.ActiveWindow().Cursor.Line) } }) } diff --git a/internal/editor/integration_insert_test.go b/internal/editor/integration_insert_test.go index 9af7015..72bae04 100644 --- a/internal/editor/integration_insert_test.go +++ b/internal/editor/integration_insert_test.go @@ -25,8 +25,8 @@ func TestEnterInsert(t *testing.T) { sendKeys(tm, "i", "X", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "Xhello" { - t.Errorf("lines[0] = %q, want 'Xhello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "Xhello" { + t.Errorf("lines[0] = %q, want 'Xhello'", m.ActiveBuffer().Lines[0]) } }) @@ -36,8 +36,8 @@ func TestEnterInsert(t *testing.T) { sendKeys(tm, "i", "X", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "heXllo" { - t.Errorf("lines[0] = %q, want 'heXllo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "heXllo" { + t.Errorf("lines[0] = %q, want 'heXllo'", m.ActiveBuffer().Lines[0]) } }) @@ -47,8 +47,8 @@ func TestEnterInsert(t *testing.T) { sendKeys(tm, "i", "X", "esc") m := getFinalModel(t, tm) - if m.CursorX() != 2 { - t.Errorf("cursor.x = %d, want 2", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 2 { + t.Errorf("cursor.x = %d, want 2", m.ActiveWindow().Cursor.Col) } }) } @@ -70,8 +70,8 @@ func TestEnterInsertAfter(t *testing.T) { sendKeys(tm, "a", "X", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "hXello" { - t.Errorf("lines[0] = %q, want 'hXello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hXello" { + t.Errorf("lines[0] = %q, want 'hXello'", m.ActiveBuffer().Lines[0]) } }) @@ -81,8 +81,8 @@ func TestEnterInsertAfter(t *testing.T) { sendKeys(tm, "a", "X", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "helXlo" { - t.Errorf("lines[0] = %q, want 'helXlo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "helXlo" { + t.Errorf("lines[0] = %q, want 'helXlo'", m.ActiveBuffer().Lines[0]) } }) } @@ -94,8 +94,8 @@ func TestEnterInsertLineStart(t *testing.T) { sendKeys(tm, "I", "X", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "Xhello" { - t.Errorf("lines[0] = %q, want 'Xhello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "Xhello" { + t.Errorf("lines[0] = %q, want 'Xhello'", m.ActiveBuffer().Lines[0]) } }) @@ -105,8 +105,8 @@ func TestEnterInsertLineStart(t *testing.T) { sendKeys(tm, "I", "X", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "Xhello" { - t.Errorf("lines[0] = %q, want 'Xhello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "Xhello" { + t.Errorf("lines[0] = %q, want 'Xhello'", m.ActiveBuffer().Lines[0]) } }) } @@ -118,8 +118,8 @@ func TestEnterInsertLineEnd(t *testing.T) { sendKeys(tm, "A", "X", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "helloX" { - t.Errorf("lines[0] = %q, want 'helloX'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "helloX" { + t.Errorf("lines[0] = %q, want 'helloX'", m.ActiveBuffer().Lines[0]) } }) @@ -129,8 +129,8 @@ func TestEnterInsertLineEnd(t *testing.T) { sendKeys(tm, "A", "X", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "helloX" { - t.Errorf("lines[0] = %q, want 'helloX'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "helloX" { + t.Errorf("lines[0] = %q, want 'helloX'", m.ActiveBuffer().Lines[0]) } }) } @@ -144,11 +144,11 @@ func TestOpenLineBelow(t *testing.T) { sendKeys(tm, "o", "n", "e", "w", "esc") m := getFinalModel(t, tm) - if m.LineCount() != 3 { - t.Errorf("len(lines) = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("len(lines) = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(1) != "new" { - t.Errorf("lines[1] = %q, want 'new'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "new" { + t.Errorf("lines[1] = %q, want 'new'", m.ActiveBuffer().Lines[1]) } }) @@ -158,11 +158,11 @@ func TestOpenLineBelow(t *testing.T) { sendKeys(tm, "o", "n", "e", "w", "esc") m := getFinalModel(t, tm) - if m.LineCount() != 4 { - t.Errorf("len(lines) = %d, want 4", m.LineCount()) + if m.ActiveBuffer().LineCount() != 4 { + t.Errorf("len(lines) = %d, want 4", m.ActiveBuffer().LineCount()) } - if m.Line(2) != "new" { - t.Errorf("lines[2] = %q, want 'new'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "new" { + t.Errorf("lines[2] = %q, want 'new'", m.ActiveBuffer().Lines[2]) } }) @@ -172,11 +172,11 @@ func TestOpenLineBelow(t *testing.T) { sendKeys(tm, "o", "n", "e", "w", "esc") m := getFinalModel(t, tm) - if m.LineCount() != 3 { - t.Errorf("len(lines) = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("len(lines) = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(2) != "new" { - t.Errorf("lines[2] = %q, want 'new'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "new" { + t.Errorf("lines[2] = %q, want 'new'", m.ActiveBuffer().Lines[2]) } }) @@ -186,11 +186,11 @@ func TestOpenLineBelow(t *testing.T) { sendKeys(tm, "o", "esc") m := getFinalModel(t, tm) - if m.CursorY() != 1 { - t.Errorf("cursor.y = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("cursor.y = %d, want 1", m.ActiveWindow().Cursor.Line) } - if m.CursorX() != 0 { - t.Errorf("cursor.x = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("cursor.x = %d, want 0", m.ActiveWindow().Cursor.Col) } }) } @@ -202,12 +202,12 @@ func TestOpenLineBelowWithCount(t *testing.T) { sendKeys(tm, "3", "o", "x", "esc") m := getFinalModel(t, tm) - if m.LineCount() != 4 { - t.Errorf("len(lines) = %d, want 4", m.LineCount()) + if m.ActiveBuffer().LineCount() != 4 { + t.Errorf("len(lines) = %d, want 4", m.ActiveBuffer().LineCount()) } for i := 1; i <= 3; i++ { - if m.Line(i) != "x" { - t.Errorf("lines[%d] = %q, want 'x'", i, m.Line(i)) + if m.ActiveBuffer().Lines[i] != "x" { + t.Errorf("lines[%d] = %q, want 'x'", i, m.ActiveBuffer().Lines[i]) } } }) @@ -218,14 +218,14 @@ func TestOpenLineBelowWithCount(t *testing.T) { sendKeys(tm, "2", "o", "a", "b", "esc") m := getFinalModel(t, tm) - if m.LineCount() != 3 { - t.Errorf("len(lines) = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("len(lines) = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(1) != "ab" { - t.Errorf("lines[1] = %q, want 'ab'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "ab" { + t.Errorf("lines[1] = %q, want 'ab'", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "ab" { - t.Errorf("lines[2] = %q, want 'ab'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "ab" { + t.Errorf("lines[2] = %q, want 'ab'", m.ActiveBuffer().Lines[2]) } }) } @@ -237,11 +237,11 @@ func TestOpenLineAbove(t *testing.T) { sendKeys(tm, "O", "n", "e", "w", "esc") m := getFinalModel(t, tm) - if m.LineCount() != 3 { - t.Errorf("len(lines) = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("len(lines) = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(1) != "new" { - t.Errorf("lines[1] = %q, want 'new'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "new" { + t.Errorf("lines[1] = %q, want 'new'", m.ActiveBuffer().Lines[1]) } }) @@ -251,11 +251,11 @@ func TestOpenLineAbove(t *testing.T) { sendKeys(tm, "O", "n", "e", "w", "esc") m := getFinalModel(t, tm) - if m.LineCount() != 3 { - t.Errorf("len(lines) = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("len(lines) = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "new" { - t.Errorf("lines[0] = %q, want 'new'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "new" { + t.Errorf("lines[0] = %q, want 'new'", m.ActiveBuffer().Lines[0]) } }) @@ -265,8 +265,8 @@ func TestOpenLineAbove(t *testing.T) { sendKeys(tm, "O", "esc") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("cursor.x = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("cursor.x = %d, want 0", m.ActiveWindow().Cursor.Col) } }) } @@ -278,12 +278,12 @@ func TestOpenLineAboveWithCount(t *testing.T) { sendKeys(tm, "3", "O", "x", "esc") m := getFinalModel(t, tm) - if m.LineCount() != 4 { - t.Errorf("len(lines) = %d, want 4", m.LineCount()) + if m.ActiveBuffer().LineCount() != 4 { + t.Errorf("len(lines) = %d, want 4", m.ActiveBuffer().LineCount()) } for i := 0; i < 3; i++ { - if m.Line(i) != "x" { - t.Errorf("lines[%d] = %q, want 'x'", i, m.Line(i)) + if m.ActiveBuffer().Lines[i] != "x" { + t.Errorf("lines[%d] = %q, want 'x'", i, m.ActiveBuffer().Lines[i]) } } }) @@ -298,14 +298,14 @@ func TestInsertModeEnter(t *testing.T) { sendKeys(tm, "i", "enter", "esc") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("len(lines) = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("len(lines) = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "hello" { - t.Errorf("lines[0] = %q, want 'hello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello" { + t.Errorf("lines[0] = %q, want 'hello'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != " world" { - t.Errorf("lines[1] = %q, want ' world'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != " world" { + t.Errorf("lines[1] = %q, want ' world'", m.ActiveBuffer().Lines[1]) } }) @@ -315,14 +315,14 @@ func TestInsertModeEnter(t *testing.T) { sendKeys(tm, "i", "enter", "esc") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("len(lines) = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("len(lines) = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "hello" { - t.Errorf("lines[0] = %q, want 'hello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello" { + t.Errorf("lines[0] = %q, want 'hello'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "" { - t.Errorf("lines[1] = %q, want ''", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "" { + t.Errorf("lines[1] = %q, want ''", m.ActiveBuffer().Lines[1]) } }) @@ -332,14 +332,14 @@ func TestInsertModeEnter(t *testing.T) { sendKeys(tm, "i", "enter", "esc") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("len(lines) = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("len(lines) = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "" { - t.Errorf("lines[0] = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("lines[0] = %q, want ''", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "hello" { - t.Errorf("lines[1] = %q, want 'hello'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "hello" { + t.Errorf("lines[1] = %q, want 'hello'", m.ActiveBuffer().Lines[1]) } }) } @@ -351,8 +351,8 @@ func TestInsertModeBackspace(t *testing.T) { sendKeys(tm, "i", "backspace", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "helo" { - t.Errorf("lines[0] = %q, want 'helo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "helo" { + t.Errorf("lines[0] = %q, want 'helo'", m.ActiveBuffer().Lines[0]) } }) @@ -362,11 +362,11 @@ func TestInsertModeBackspace(t *testing.T) { sendKeys(tm, "i", "backspace", "esc") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("len(lines) = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("len(lines) = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "helloworld" { - t.Errorf("lines[0] = %q, want 'helloworld'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "helloworld" { + t.Errorf("lines[0] = %q, want 'helloworld'", m.ActiveBuffer().Lines[0]) } }) @@ -376,8 +376,8 @@ func TestInsertModeBackspace(t *testing.T) { sendKeys(tm, "i", "backspace", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "hello" { - t.Errorf("lines[0] = %q, want 'hello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello" { + t.Errorf("lines[0] = %q, want 'hello'", m.ActiveBuffer().Lines[0]) } }) @@ -387,8 +387,8 @@ func TestInsertModeBackspace(t *testing.T) { sendKeys(tm, "i", "backspace", "backspace", "backspace", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "he" { - t.Errorf("lines[0] = %q, want 'he'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "he" { + t.Errorf("lines[0] = %q, want 'he'", m.ActiveBuffer().Lines[0]) } }) } @@ -400,8 +400,8 @@ func TestInsertModeDelete(t *testing.T) { sendKeys(tm, "i", "delete", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "word" { - t.Errorf("lines[0] = %q, want 'word'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "word" { + t.Errorf("lines[0] = %q, want 'word'", m.ActiveBuffer().Lines[0]) } }) @@ -411,11 +411,11 @@ func TestInsertModeDelete(t *testing.T) { sendKeys(tm, "i", "delete", "esc") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("len(lines) = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("len(lines) = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "helloworld" { - t.Errorf("lines[0] = %q, want 'helloworld'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "helloworld" { + t.Errorf("lines[0] = %q, want 'helloworld'", m.ActiveBuffer().Lines[0]) } }) @@ -425,11 +425,11 @@ func TestInsertModeDelete(t *testing.T) { sendKeys(tm, "i", "delete", "esc") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("len(lines) = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("len(lines) = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "world" { - t.Errorf("lines[0] = %q, want 'world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "world" { + t.Errorf("lines[0] = %q, want 'world'", m.ActiveBuffer().Lines[0]) } }) @@ -439,8 +439,8 @@ func TestInsertModeDelete(t *testing.T) { sendKeys(tm, "i", "delete", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "hello" { - t.Errorf("lines[0] = %q, want 'hello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello" { + t.Errorf("lines[0] = %q, want 'hello'", m.ActiveBuffer().Lines[0]) } }) @@ -450,8 +450,8 @@ func TestInsertModeDelete(t *testing.T) { sendKeys(tm, "i", "delete", "delete", "delete", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "ho" { - t.Errorf("lines[0] = %q, want 'he'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "ho" { + t.Errorf("lines[0] = %q, want 'he'", m.ActiveBuffer().Lines[0]) } }) @@ -464,8 +464,8 @@ func TestInsertModeArrowKeys(t *testing.T) { sendKeys(tm, "i", "left", "X", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "heXllo" { - t.Errorf("lines[0] = %q, want 'heXllo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "heXllo" { + t.Errorf("lines[0] = %q, want 'heXllo'", m.ActiveBuffer().Lines[0]) } }) @@ -475,8 +475,8 @@ func TestInsertModeArrowKeys(t *testing.T) { sendKeys(tm, "i", "right", "X", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "heXllo" { - t.Errorf("lines[0] = %q, want 'heXllo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "heXllo" { + t.Errorf("lines[0] = %q, want 'heXllo'", m.ActiveBuffer().Lines[0]) } }) @@ -486,11 +486,11 @@ func TestInsertModeArrowKeys(t *testing.T) { sendKeys(tm, "i", "up", "X", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "heXllo" { - t.Errorf("lines[0] = %q, want 'heXllo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "heXllo" { + t.Errorf("lines[0] = %q, want 'heXllo'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "world" { - t.Errorf("lines[1] = %q, want 'world'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "world" { + t.Errorf("lines[1] = %q, want 'world'", m.ActiveBuffer().Lines[1]) } }) @@ -500,11 +500,11 @@ func TestInsertModeArrowKeys(t *testing.T) { sendKeys(tm, "i", "down", "X", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "hello" { - t.Errorf("lines[0] = %q, want 'hello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello" { + t.Errorf("lines[0] = %q, want 'hello'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "woXrld" { - t.Errorf("lines[1] = %q, want 'woXrld'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "woXrld" { + t.Errorf("lines[1] = %q, want 'woXrld'", m.ActiveBuffer().Lines[1]) } }) @@ -514,8 +514,8 @@ func TestInsertModeArrowKeys(t *testing.T) { sendKeys(tm, "i", "left", "X", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "Xhello" { - t.Errorf("lines[0] = %q, want 'Xhello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "Xhello" { + t.Errorf("lines[0] = %q, want 'Xhello'", m.ActiveBuffer().Lines[0]) } }) @@ -525,8 +525,8 @@ func TestInsertModeArrowKeys(t *testing.T) { sendKeys(tm, "a", "right", "X", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "helloX" { - t.Errorf("lines[0] = %q, want 'helloX'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "helloX" { + t.Errorf("lines[0] = %q, want 'helloX'", m.ActiveBuffer().Lines[0]) } }) @@ -536,8 +536,8 @@ func TestInsertModeArrowKeys(t *testing.T) { sendKeys(tm, "i", "up", "X", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "heXllo" { - t.Errorf("lines[0] = %q, want 'heXllo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "heXllo" { + t.Errorf("lines[0] = %q, want 'heXllo'", m.ActiveBuffer().Lines[0]) } }) @@ -547,8 +547,8 @@ func TestInsertModeArrowKeys(t *testing.T) { sendKeys(tm, "i", "down", "X", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "heXllo" { - t.Errorf("lines[0] = %q, want 'heXllo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "heXllo" { + t.Errorf("lines[0] = %q, want 'heXllo'", m.ActiveBuffer().Lines[0]) } }) @@ -558,8 +558,8 @@ func TestInsertModeArrowKeys(t *testing.T) { sendKeys(tm, "i", "up", "X", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "hiX" { - t.Errorf("lines[0] = %q, want 'hiX'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hiX" { + t.Errorf("lines[0] = %q, want 'hiX'", m.ActiveBuffer().Lines[0]) } }) @@ -569,8 +569,8 @@ func TestInsertModeArrowKeys(t *testing.T) { sendKeys(tm, "i", "down", "X", "esc") m := getFinalModel(t, tm) - if m.Line(1) != "hiX" { - t.Errorf("lines[1] = %q, want 'hiX'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "hiX" { + t.Errorf("lines[1] = %q, want 'hiX'", m.ActiveBuffer().Lines[1]) } }) @@ -580,8 +580,8 @@ func TestInsertModeArrowKeys(t *testing.T) { sendKeys(tm, "i", "right", "right", "down", "X", "esc") m := getFinalModel(t, tm) - if m.Line(1) != "woXrld" { - t.Errorf("lines[1] = %q, want 'woXrld'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "woXrld" { + t.Errorf("lines[1] = %q, want 'woXrld'", m.ActiveBuffer().Lines[1]) } }) } @@ -593,11 +593,11 @@ func TestInsertModeDeletePreviousWord(t *testing.T) { sendKeys(tm, "a", "ctrl+w", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "hello " { - t.Errorf("lines[0] = %q, want 'hello '", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello " { + t.Errorf("lines[0] = %q, want 'hello '", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 5 { - t.Errorf("CursorX() = %d, want '5'", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 5 { + t.Errorf("CursorX() = %d, want '5'", m.ActiveWindow().Cursor.Col) } }) @@ -607,11 +607,11 @@ func TestInsertModeDeletePreviousWord(t *testing.T) { sendKeys(tm, "a", "ctrl+w", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "" { - t.Errorf("lines[0] = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("lines[0] = %q, want ''", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want '0'", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want '0'", m.ActiveWindow().Cursor.Col) } }) @@ -621,11 +621,11 @@ func TestInsertModeDeletePreviousWord(t *testing.T) { sendKeys(tm, "a", "ctrl+w", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "hello wo" { - t.Errorf("lines[0] = %q, want 'hello wo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello wo" { + t.Errorf("lines[0] = %q, want 'hello wo'", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 7 { - t.Errorf("CursorX() = %d, want '7'", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 7 { + t.Errorf("CursorX() = %d, want '7'", m.ActiveWindow().Cursor.Col) } }) @@ -635,14 +635,14 @@ func TestInsertModeDeletePreviousWord(t *testing.T) { sendKeys(tm, "a", "ctrl+w", "esc") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want '1'", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want '1'", m.ActiveBuffer().LineCount()) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want '0'", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want '0'", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want '0'", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want '0'", m.ActiveWindow().Cursor.Line) } }) @@ -652,17 +652,17 @@ func TestInsertModeDeletePreviousWord(t *testing.T) { sendKeys(tm, "a", "ctrl+w", "esc") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want '1'", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want '1'", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %s, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %s, want ''", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want '0'", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want '0'", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want '0'", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want '0'", m.ActiveWindow().Cursor.Line) } }) @@ -672,11 +672,11 @@ func TestInsertModeDeletePreviousWord(t *testing.T) { sendKeys(tm, "i", "ctrl+w", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "hello" { - t.Errorf("lines[0] = %q, want 'hello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello" { + t.Errorf("lines[0] = %q, want 'hello'", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -686,11 +686,11 @@ func TestInsertModeDeletePreviousWord(t *testing.T) { sendKeys(tm, "i", "ctrl+w", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "lo" { - t.Errorf("lines[0] = %q, want 'lo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "lo" { + t.Errorf("lines[0] = %q, want 'lo'", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -700,11 +700,11 @@ func TestInsertModeDeletePreviousWord(t *testing.T) { sendKeys(tm, "a", "ctrl+w", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "..." { - t.Errorf("lines[0] = %q, want '...'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "..." { + t.Errorf("lines[0] = %q, want '...'", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 2 { - t.Errorf("CursorX() = %d, want 2", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 2 { + t.Errorf("CursorX() = %d, want 2", m.ActiveWindow().Cursor.Col) } }) @@ -714,11 +714,11 @@ func TestInsertModeDeletePreviousWord(t *testing.T) { sendKeys(tm, "a", "ctrl+w", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "hello\t" { - t.Errorf("lines[0] = %q, want 'hello\\t'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello\t" { + t.Errorf("lines[0] = %q, want 'hello\\t'", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 5 { - t.Errorf("CursorX() = %d, want 5", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 5 { + t.Errorf("CursorX() = %d, want 5", m.ActiveWindow().Cursor.Col) } }) @@ -728,17 +728,17 @@ func TestInsertModeDeletePreviousWord(t *testing.T) { sendKeys(tm, "i", "ctrl+w", "esc") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "helloworld" { - t.Errorf("lines[0] = %q, want 'helloworld'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "helloworld" { + t.Errorf("lines[0] = %q, want 'helloworld'", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -748,11 +748,11 @@ func TestInsertModeDeletePreviousWord(t *testing.T) { sendKeys(tm, "a", "ctrl+w", "esc") m := getFinalModel(t, tm) - if m.Line(0) != "" { - t.Errorf("lines[0] = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("lines[0] = %q, want ''", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) } diff --git a/internal/editor/integration_motion_basic_test.go b/internal/editor/integration_motion_basic_test.go index f5bf615..843d8c6 100644 --- a/internal/editor/integration_motion_basic_test.go +++ b/internal/editor/integration_motion_basic_test.go @@ -12,8 +12,8 @@ func TestMoveDown(t *testing.T) { sendKeys(tm, "j") m := getFinalModel(t, tm) - if m.CursorY() != 1 { - t.Errorf("cursor.y = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("cursor.y = %d, want 1", m.ActiveWindow().Cursor.Line) } }) @@ -22,8 +22,8 @@ func TestMoveDown(t *testing.T) { sendKeys(tm, "j", "j", "j", "j") m := getFinalModel(t, tm) - if m.CursorY() != 4 { - t.Errorf("cursor.y = %d, want 4", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 4 { + t.Errorf("cursor.y = %d, want 4", m.ActiveWindow().Cursor.Line) } }) @@ -32,8 +32,8 @@ func TestMoveDown(t *testing.T) { sendKeys(tm, "j", "j", "j", "j", "j", "j", "j", "j", "j") m := getFinalModel(t, tm) - if m.CursorY() != 5 { - t.Errorf("cursor.y = %d, want 5", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 5 { + t.Errorf("cursor.y = %d, want 5", m.ActiveWindow().Cursor.Line) } }) } @@ -44,8 +44,8 @@ func TestMoveDownWithCount(t *testing.T) { sendKeys(tm, "3", "j") m := getFinalModel(t, tm) - if m.CursorY() != 3 { - t.Errorf("cursor.y = %d, want 3", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 3 { + t.Errorf("cursor.y = %d, want 3", m.ActiveWindow().Cursor.Line) } }) @@ -54,8 +54,8 @@ func TestMoveDownWithCount(t *testing.T) { sendKeys(tm, "1", "0", "j") m := getFinalModel(t, tm) - if m.CursorY() != 5 { - t.Errorf("cursor.y = %d, want 5", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 5 { + t.Errorf("cursor.y = %d, want 5", m.ActiveWindow().Cursor.Line) } }) } @@ -69,8 +69,8 @@ func TestMoveDownWithOverflow(t *testing.T) { m := getFinalModel(t, tm) want := len(lines[1]) - if m.CursorX() != want { - t.Errorf("cursor.x = %d, want %d", m.CursorX(), want) + if m.ActiveWindow().Cursor.Col != want { + t.Errorf("cursor.x = %d, want %d", m.ActiveWindow().Cursor.Col, want) } }) @@ -79,8 +79,8 @@ func TestMoveDownWithOverflow(t *testing.T) { sendKeys(tm, "j") m := getFinalModel(t, tm) - if m.CursorX() != 3 { - t.Errorf("cursor.x = %d, want 3", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 3 { + t.Errorf("cursor.x = %d, want 3", m.ActiveWindow().Cursor.Col) } }) } @@ -91,8 +91,8 @@ func TestMoveUp(t *testing.T) { sendKeys(tm, "k") m := getFinalModel(t, tm) - if m.CursorY() != 1 { - t.Errorf("cursor.y = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("cursor.y = %d, want 1", m.ActiveWindow().Cursor.Line) } }) @@ -101,8 +101,8 @@ func TestMoveUp(t *testing.T) { sendKeys(tm, "k", "k", "k", "k") m := getFinalModel(t, tm) - if m.CursorY() != 0 { - t.Errorf("cursor.y = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("cursor.y = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -111,8 +111,8 @@ func TestMoveUp(t *testing.T) { sendKeys(tm, "k", "k", "k") m := getFinalModel(t, tm) - if m.CursorY() != 0 { - t.Errorf("cursor.y = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("cursor.y = %d, want 0", m.ActiveWindow().Cursor.Line) } }) } @@ -123,8 +123,8 @@ func TestMoveUpWithCount(t *testing.T) { sendKeys(tm, "3", "k") m := getFinalModel(t, tm) - if m.CursorY() != 2 { - t.Errorf("cursor.y = %d, want 2", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 2 { + t.Errorf("cursor.y = %d, want 2", m.ActiveWindow().Cursor.Line) } }) @@ -133,8 +133,8 @@ func TestMoveUpWithCount(t *testing.T) { sendKeys(tm, "1", "0", "k") m := getFinalModel(t, tm) - if m.CursorY() != 0 { - t.Errorf("cursor.y = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("cursor.y = %d, want 0", m.ActiveWindow().Cursor.Line) } }) } @@ -148,8 +148,8 @@ func TestMoveUpWithOverflow(t *testing.T) { m := getFinalModel(t, tm) want := len(lines[0]) - if m.CursorX() != want { - t.Errorf("cursor.x = %d, want %d", m.CursorX(), want) + if m.ActiveWindow().Cursor.Col != want { + t.Errorf("cursor.x = %d, want %d", m.ActiveWindow().Cursor.Col, want) } }) @@ -158,8 +158,8 @@ func TestMoveUpWithOverflow(t *testing.T) { sendKeys(tm, "k") m := getFinalModel(t, tm) - if m.CursorX() != 3 { - t.Errorf("cursor.x = %d, want 3", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 3 { + t.Errorf("cursor.x = %d, want 3", m.ActiveWindow().Cursor.Col) } }) } @@ -170,8 +170,8 @@ func TestMoveRight(t *testing.T) { sendKeys(tm, "l") m := getFinalModel(t, tm) - if m.CursorX() != 1 { - t.Errorf("cursor.x = %d, want 1", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 1 { + t.Errorf("cursor.x = %d, want 1", m.ActiveWindow().Cursor.Col) } }) @@ -180,8 +180,8 @@ func TestMoveRight(t *testing.T) { sendKeys(tm, "l", "l", "l", "l") m := getFinalModel(t, tm) - if m.CursorX() != 4 { - t.Errorf("cursor.x = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("cursor.x = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -192,8 +192,8 @@ func TestMoveRight(t *testing.T) { m := getFinalModel(t, tm) want := len(lines[0]) - if m.CursorX() != want { - t.Errorf("cursor.x = %d, want %d", m.CursorX(), want) + if m.ActiveWindow().Cursor.Col != want { + t.Errorf("cursor.x = %d, want %d", m.ActiveWindow().Cursor.Col, want) } }) } @@ -204,8 +204,8 @@ func TestMoveRightWithCount(t *testing.T) { sendKeys(tm, "3", "l") m := getFinalModel(t, tm) - if m.CursorX() != 3 { - t.Errorf("cursor.x = %d, want 3", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 3 { + t.Errorf("cursor.x = %d, want 3", m.ActiveWindow().Cursor.Col) } }) @@ -216,8 +216,8 @@ func TestMoveRightWithCount(t *testing.T) { m := getFinalModel(t, tm) want := len(lines[0]) - if m.CursorX() != want { - t.Errorf("cursor.x = %d, want %d", m.CursorX(), want) + if m.ActiveWindow().Cursor.Col != want { + t.Errorf("cursor.x = %d, want %d", m.ActiveWindow().Cursor.Col, want) } }) } @@ -228,8 +228,8 @@ func TestMoveLeft(t *testing.T) { sendKeys(tm, "h") m := getFinalModel(t, tm) - if m.CursorX() != 2 { - t.Errorf("cursor.x = %d, want 2", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 2 { + t.Errorf("cursor.x = %d, want 2", m.ActiveWindow().Cursor.Col) } }) @@ -238,8 +238,8 @@ func TestMoveLeft(t *testing.T) { sendKeys(tm, "h", "h", "h", "h") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("cursor.x = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("cursor.x = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -248,8 +248,8 @@ func TestMoveLeft(t *testing.T) { sendKeys(tm, "h", "h", "h") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("cursor.x = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("cursor.x = %d, want 0", m.ActiveWindow().Cursor.Col) } }) } @@ -260,8 +260,8 @@ func TestMoveLeftWithCount(t *testing.T) { sendKeys(tm, "3", "h") m := getFinalModel(t, tm) - if m.CursorX() != 2 { - t.Errorf("cursor.x = %d, want 2", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 2 { + t.Errorf("cursor.x = %d, want 2", m.ActiveWindow().Cursor.Col) } }) @@ -270,8 +270,8 @@ func TestMoveLeftWithCount(t *testing.T) { sendKeys(tm, "1", "0", "h") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("cursor.x = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("cursor.x = %d, want 0", m.ActiveWindow().Cursor.Col) } }) } diff --git a/internal/editor/integration_motion_jump_test.go b/internal/editor/integration_motion_jump_test.go index 7e3f1de..46ccf4a 100644 --- a/internal/editor/integration_motion_jump_test.go +++ b/internal/editor/integration_motion_jump_test.go @@ -14,8 +14,8 @@ func TestMoveToBottom(t *testing.T) { sendKeys(tm, "G") m := getFinalModel(t, tm) - if m.CursorY() != 5 { - t.Errorf("CursorY() = %d, want 5", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 5 { + t.Errorf("CursorY() = %d, want 5", m.ActiveWindow().Cursor.Line) } }) @@ -24,8 +24,8 @@ func TestMoveToBottom(t *testing.T) { sendKeys(tm, "G") m := getFinalModel(t, tm) - if m.CursorY() != 5 { - t.Errorf("CursorY() = %d, want 5", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 5 { + t.Errorf("CursorY() = %d, want 5", m.ActiveWindow().Cursor.Line) } }) @@ -34,8 +34,8 @@ func TestMoveToBottom(t *testing.T) { sendKeys(tm, "G") m := getFinalModel(t, tm) - if m.CursorY() != 5 { - t.Errorf("CursorY() = %d, want 5", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 5 { + t.Errorf("CursorY() = %d, want 5", m.ActiveWindow().Cursor.Line) } }) @@ -45,12 +45,12 @@ func TestMoveToBottom(t *testing.T) { sendKeys(tm, "G") m := getFinalModel(t, tm) - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want 1", m.ActiveWindow().Cursor.Line) } want := len(lines[1]) - if m.CursorX() != want { - t.Errorf("CursorX() = %d, want %d", m.CursorX(), want) + if m.ActiveWindow().Cursor.Col != want { + t.Errorf("CursorX() = %d, want %d", m.ActiveWindow().Cursor.Col, want) } }) @@ -60,8 +60,8 @@ func TestMoveToBottom(t *testing.T) { sendKeys(tm, "G") m := getFinalModel(t, tm) - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) } @@ -72,8 +72,8 @@ func TestMoveToTop(t *testing.T) { sendKeys(tm, "g", "g") m := getFinalModel(t, tm) - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -82,8 +82,8 @@ func TestMoveToTop(t *testing.T) { sendKeys(tm, "g", "g") m := getFinalModel(t, tm) - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -92,8 +92,8 @@ func TestMoveToTop(t *testing.T) { sendKeys(tm, "g", "g") m := getFinalModel(t, tm) - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -103,12 +103,12 @@ func TestMoveToTop(t *testing.T) { sendKeys(tm, "g", "g") m := getFinalModel(t, tm) - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } want := len(lines[0]) - if m.CursorX() != want { - t.Errorf("CursorX() = %d, want %d", m.CursorX(), want) + if m.ActiveWindow().Cursor.Col != want { + t.Errorf("CursorX() = %d, want %d", m.ActiveWindow().Cursor.Col, want) } }) } @@ -121,8 +121,8 @@ func TestMoveToLineStart(t *testing.T) { sendKeys(tm, "0") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -132,8 +132,8 @@ func TestMoveToLineStart(t *testing.T) { sendKeys(tm, "0") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -142,8 +142,8 @@ func TestMoveToLineStart(t *testing.T) { sendKeys(tm, "0") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -153,8 +153,8 @@ func TestMoveToLineStart(t *testing.T) { sendKeys(tm, "0") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -163,8 +163,8 @@ func TestMoveToLineStart(t *testing.T) { sendKeys(tm, "0") m := getFinalModel(t, tm) - if m.CursorY() != 2 { - t.Errorf("CursorY() = %d, want 2", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 2 { + t.Errorf("CursorY() = %d, want 2", m.ActiveWindow().Cursor.Line) } }) } @@ -177,8 +177,8 @@ func TestMoveToLineEnd(t *testing.T) { m := getFinalModel(t, tm) want := len(lines[0]) - if m.CursorX() != want { - t.Errorf("CursorX() = %d, want %d", m.CursorX(), want) + if m.ActiveWindow().Cursor.Col != want { + t.Errorf("CursorX() = %d, want %d", m.ActiveWindow().Cursor.Col, want) } }) @@ -189,8 +189,8 @@ func TestMoveToLineEnd(t *testing.T) { m := getFinalModel(t, tm) want := len(lines[0]) - if m.CursorX() != want { - t.Errorf("CursorX() = %d, want %d", m.CursorX(), want) + if m.ActiveWindow().Cursor.Col != want { + t.Errorf("CursorX() = %d, want %d", m.ActiveWindow().Cursor.Col, want) } }) @@ -201,8 +201,8 @@ func TestMoveToLineEnd(t *testing.T) { m := getFinalModel(t, tm) want := len(lines[0]) - if m.CursorX() != want { - t.Errorf("CursorX() = %d, want %d", m.CursorX(), want) + if m.ActiveWindow().Cursor.Col != want { + t.Errorf("CursorX() = %d, want %d", m.ActiveWindow().Cursor.Col, want) } }) @@ -212,8 +212,8 @@ func TestMoveToLineEnd(t *testing.T) { sendKeys(tm, "$") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -222,8 +222,8 @@ func TestMoveToLineEnd(t *testing.T) { sendKeys(tm, "$") m := getFinalModel(t, tm) - if m.CursorY() != 2 { - t.Errorf("CursorY() = %d, want 2", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 2 { + t.Errorf("CursorY() = %d, want 2", m.ActiveWindow().Cursor.Line) } }) } @@ -235,8 +235,8 @@ func TestMoveToLineContentStart(t *testing.T) { sendKeys(tm, "_") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -246,8 +246,8 @@ func TestMoveToLineContentStart(t *testing.T) { sendKeys(tm, "_") m := getFinalModel(t, tm) - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -257,8 +257,8 @@ func TestMoveToLineContentStart(t *testing.T) { sendKeys(tm, "_") m := getFinalModel(t, tm) - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -268,8 +268,8 @@ func TestMoveToLineContentStart(t *testing.T) { sendKeys(tm, "_") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -279,8 +279,8 @@ func TestMoveToLineContentStart(t *testing.T) { sendKeys(tm, "_") m := getFinalModel(t, tm) - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -290,8 +290,8 @@ func TestMoveToLineContentStart(t *testing.T) { sendKeys(tm, "_") m := getFinalModel(t, tm) - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -301,8 +301,8 @@ func TestMoveToLineContentStart(t *testing.T) { sendKeys(tm, "_") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) } @@ -314,8 +314,8 @@ func TestMoveToLineContentStartAlias(t *testing.T) { sendKeys(tm, "^") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -325,8 +325,8 @@ func TestMoveToLineContentStartAlias(t *testing.T) { sendKeys(tm, "^") m := getFinalModel(t, tm) - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -336,8 +336,8 @@ func TestMoveToLineContentStartAlias(t *testing.T) { sendKeys(tm, "^") m := getFinalModel(t, tm) - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -347,8 +347,8 @@ func TestMoveToLineContentStartAlias(t *testing.T) { sendKeys(tm, "^") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -358,8 +358,8 @@ func TestMoveToLineContentStartAlias(t *testing.T) { sendKeys(tm, "^") m := getFinalModel(t, tm) - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -369,8 +369,8 @@ func TestMoveToLineContentStartAlias(t *testing.T) { sendKeys(tm, "^") m := getFinalModel(t, tm) - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -380,8 +380,8 @@ func TestMoveToLineContentStartAlias(t *testing.T) { sendKeys(tm, "^") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) } @@ -400,8 +400,8 @@ func TestMoveToColumn(t *testing.T) { m := getFinalModel(t, tm) // | with no count = 1| = column 1 = index 0 - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -411,8 +411,8 @@ func TestMoveToColumn(t *testing.T) { sendKeys(tm, "1", "|") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -423,8 +423,8 @@ func TestMoveToColumn(t *testing.T) { m := getFinalModel(t, tm) // Column 5 = index 4 (the 'o' in hello) - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -435,8 +435,8 @@ func TestMoveToColumn(t *testing.T) { m := getFinalModel(t, tm) // Column 10 = index 9 (the 'l' in world) - if m.CursorX() != 9 { - t.Errorf("CursorX() = %d, want 9", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 9 { + t.Errorf("CursorX() = %d, want 9", m.ActiveWindow().Cursor.Col) } }) @@ -446,8 +446,8 @@ func TestMoveToColumn(t *testing.T) { sendKeys(tm, "|") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -457,8 +457,8 @@ func TestMoveToColumn(t *testing.T) { sendKeys(tm, "5", "|") m := getFinalModel(t, tm) - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) } @@ -471,8 +471,8 @@ func TestMoveToColumnClamp(t *testing.T) { m := getFinalModel(t, tm) // Column 20 exceeds line length, should clamp to last char (index 4) - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -483,8 +483,8 @@ func TestMoveToColumnClamp(t *testing.T) { m := getFinalModel(t, tm) // Should clamp to last char (index 10) - if m.CursorX() != 10 { - t.Errorf("CursorX() = %d, want 10", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 10 { + t.Errorf("CursorX() = %d, want 10", m.ActiveWindow().Cursor.Col) } }) @@ -495,8 +495,8 @@ func TestMoveToColumnClamp(t *testing.T) { m := getFinalModel(t, tm) // Column 6 = index 5, but line only has 5 chars (max index 4) - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -506,8 +506,8 @@ func TestMoveToColumnClamp(t *testing.T) { sendKeys(tm, "|") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -517,8 +517,8 @@ func TestMoveToColumnClamp(t *testing.T) { sendKeys(tm, "5", "|") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -529,8 +529,8 @@ func TestMoveToColumnClamp(t *testing.T) { m := getFinalModel(t, tm) // Column 3 = index 2, but line only has 2 chars (max index 1) - if m.CursorX() != 1 { - t.Errorf("CursorX() = %d, want 1", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 1 { + t.Errorf("CursorX() = %d, want 1", m.ActiveWindow().Cursor.Col) } }) } @@ -542,8 +542,8 @@ func TestMoveToColumnPreservesLine(t *testing.T) { sendKeys(tm, "|") m := getFinalModel(t, tm) - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want 1", m.ActiveWindow().Cursor.Line) } }) @@ -553,8 +553,8 @@ func TestMoveToColumnPreservesLine(t *testing.T) { sendKeys(tm, "5", "|") m := getFinalModel(t, tm) - if m.CursorY() != 2 { - t.Errorf("CursorY() = %d, want 2", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 2 { + t.Errorf("CursorY() = %d, want 2", m.ActiveWindow().Cursor.Line) } }) @@ -564,11 +564,11 @@ func TestMoveToColumnPreservesLine(t *testing.T) { sendKeys(tm, "|") m := getFinalModel(t, tm) - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want 1", m.ActiveWindow().Cursor.Line) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) } @@ -581,8 +581,8 @@ func TestMoveToColumnWithWhitespace(t *testing.T) { m := getFinalModel(t, tm) // Column 5 = index 4 = 'h' in " hello" - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -593,8 +593,8 @@ func TestMoveToColumnWithWhitespace(t *testing.T) { m := getFinalModel(t, tm) // Column 3 = index 2 = third space - if m.CursorX() != 2 { - t.Errorf("CursorX() = %d, want 2", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 2 { + t.Errorf("CursorX() = %d, want 2", m.ActiveWindow().Cursor.Col) } }) @@ -605,8 +605,8 @@ func TestMoveToColumnWithWhitespace(t *testing.T) { m := getFinalModel(t, tm) // | goes to column 1 = index 0 = the tab - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -617,8 +617,8 @@ func TestMoveToColumnWithWhitespace(t *testing.T) { m := getFinalModel(t, tm) // Column 2 = index 1 = 'h' in "\thello" - if m.CursorX() != 1 { - t.Errorf("CursorX() = %d, want 1", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 1 { + t.Errorf("CursorX() = %d, want 1", m.ActiveWindow().Cursor.Col) } }) } @@ -633,8 +633,8 @@ func TestMoveToColumnWithOperator(t *testing.T) { // Deletes from column 1 to current position (exclusive), so "hello" deleted // Result depends on inclusive/exclusive behavior // In Vim: d| from col 5 deletes chars 0-4, leaving " world" - if m.Line(0) != " world" { - t.Errorf("Line(0) = %q, want ' world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != " world" { + t.Errorf("Line(0) = %q, want ' world'", m.ActiveBuffer().Lines[0]) } }) @@ -646,8 +646,8 @@ func TestMoveToColumnWithOperator(t *testing.T) { m := getFinalModel(t, tm) // Deletes from cursor (0) to column 5 (index 4), so "hell" deleted // Result: "o world" - if m.Line(0) != "o world" { - t.Errorf("Line(0) = %q, want 'o world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "o world" { + t.Errorf("Line(0) = %q, want 'o world'", m.ActiveBuffer().Lines[0]) } }) @@ -691,11 +691,11 @@ func TestMoveToColumnInVisualMode(t *testing.T) { sendKeys(tm, "v", "5", "|") m := getFinalModel(t, tm) - if m.AnchorX() != 0 { - t.Errorf("AnchorX() = %d, want 0", m.AnchorX()) + if m.ActiveWindow().Anchor.Col != 0 { + t.Errorf("AnchorX() = %d, want 0", m.ActiveWindow().Anchor.Col) } - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -705,11 +705,11 @@ func TestMoveToColumnInVisualMode(t *testing.T) { sendKeys(tm, "v", "|") m := getFinalModel(t, tm) - if m.AnchorX() != 5 { - t.Errorf("AnchorX() = %d, want 5", m.AnchorX()) + if m.ActiveWindow().Anchor.Col != 5 { + t.Errorf("AnchorX() = %d, want 5", m.ActiveWindow().Anchor.Col) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -720,8 +720,8 @@ func TestMoveToColumnInVisualMode(t *testing.T) { m := getFinalModel(t, tm) // Visual selection from 0 to 4 inclusive, delete "hello" - if m.Line(0) != " world" { - t.Errorf("Line(0) = %q, want ' world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != " world" { + t.Errorf("Line(0) = %q, want ' world'", m.ActiveBuffer().Lines[0]) } }) } diff --git a/internal/editor/integration_motion_word_test.go b/internal/editor/integration_motion_word_test.go index 2ec8617..eea63c0 100644 --- a/internal/editor/integration_motion_word_test.go +++ b/internal/editor/integration_motion_word_test.go @@ -15,8 +15,8 @@ func TestMoveForwardWord(t *testing.T) { sendKeys(tm, "w") m := getFinalModel(t, tm) - if m.CursorX() != 6 { - t.Errorf("m.CursorX() = %d, want 6", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 6 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 6", m.ActiveWindow().Cursor.Col) } }) @@ -26,8 +26,8 @@ func TestMoveForwardWord(t *testing.T) { sendKeys(tm, "w", "w", "w") m := getFinalModel(t, tm) - if m.CursorX() != 18 { - t.Errorf("m.CursorX() = %d, want 18", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 18 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 18", m.ActiveWindow().Cursor.Col) } }) @@ -37,11 +37,11 @@ func TestMoveForwardWord(t *testing.T) { sendKeys(tm, "w") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("m.CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 0", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 1 { - t.Errorf("m.CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("m.ActiveWindow().Cursor.Line = %d, want 1", m.ActiveWindow().Cursor.Line) } }) @@ -51,11 +51,11 @@ func TestMoveForwardWord(t *testing.T) { sendKeys(tm, "w") m := getFinalModel(t, tm) - if m.CursorX() != 5 { - t.Errorf("m.CursorX() = %d, want 5", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 5 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 5", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 0 { - t.Errorf("m.CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("m.ActiveWindow().Cursor.Line = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -65,8 +65,8 @@ func TestMoveForwardWord(t *testing.T) { sendKeys(tm, "w") m := getFinalModel(t, tm) - if m.CursorX() != 5 { - t.Errorf("m.CursorX() = %d, want 5", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 5 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 5", m.ActiveWindow().Cursor.Col) } }) @@ -76,8 +76,8 @@ func TestMoveForwardWord(t *testing.T) { sendKeys(tm, "w") m := getFinalModel(t, tm) - if m.CursorX() != 11 { - t.Errorf("m.CursorX() = %d, want 11", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 11 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 11", m.ActiveWindow().Cursor.Col) } }) @@ -87,8 +87,8 @@ func TestMoveForwardWord(t *testing.T) { sendKeys(tm, "w") m := getFinalModel(t, tm) - if m.CursorX() != 1 { - t.Errorf("m.CursorX() = %d, want 1", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 1 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 1", m.ActiveWindow().Cursor.Col) } }) @@ -98,8 +98,8 @@ func TestMoveForwardWord(t *testing.T) { sendKeys(tm, "w") m := getFinalModel(t, tm) - if m.CursorX() != 6 { - t.Errorf("m.CursorX() = %d, want 6", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 6 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 6", m.ActiveWindow().Cursor.Col) } }) } @@ -111,8 +111,8 @@ func TestMoveToWordEnd(t *testing.T) { sendKeys(tm, "e") m := getFinalModel(t, tm) - if m.CursorX() != 4 { - t.Errorf("m.CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -122,8 +122,8 @@ func TestMoveToWordEnd(t *testing.T) { sendKeys(tm, "e", "e", "e") m := getFinalModel(t, tm) - if m.CursorX() != 16 { - t.Errorf("m.CursorX() = %d, want 16", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 16 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 16", m.ActiveWindow().Cursor.Col) } }) @@ -133,11 +133,11 @@ func TestMoveToWordEnd(t *testing.T) { sendKeys(tm, "e") m := getFinalModel(t, tm) - if m.CursorX() != 4 { - t.Errorf("m.CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 4", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 1 { - t.Errorf("m.CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("m.ActiveWindow().Cursor.Line = %d, want 1", m.ActiveWindow().Cursor.Line) } }) @@ -147,11 +147,11 @@ func TestMoveToWordEnd(t *testing.T) { sendKeys(tm, "e") m := getFinalModel(t, tm) - if m.CursorX() != 4 { - t.Errorf("m.CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 4", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 0 { - t.Errorf("m.CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("m.ActiveWindow().Cursor.Line = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -161,8 +161,8 @@ func TestMoveToWordEnd(t *testing.T) { sendKeys(tm, "e") m := getFinalModel(t, tm) - if m.CursorX() != 4 { - t.Errorf("m.CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -172,8 +172,8 @@ func TestMoveToWordEnd(t *testing.T) { sendKeys(tm, "e") m := getFinalModel(t, tm) - if m.CursorX() != 1 { - t.Errorf("m.CursorX() = %d, want 1", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 1 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 1", m.ActiveWindow().Cursor.Col) } }) @@ -183,8 +183,8 @@ func TestMoveToWordEnd(t *testing.T) { sendKeys(tm, "e") m := getFinalModel(t, tm) - if m.CursorX() != 10 { - t.Errorf("m.CursorX() = %d, want 10", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 10 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 10", m.ActiveWindow().Cursor.Col) } }) @@ -194,8 +194,8 @@ func TestMoveToWordEnd(t *testing.T) { sendKeys(tm, "e") m := getFinalModel(t, tm) - if m.CursorX() != 5 { - t.Errorf("m.CursorX() = %d, want 5", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 5 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 5", m.ActiveWindow().Cursor.Col) } }) @@ -205,8 +205,8 @@ func TestMoveToWordEnd(t *testing.T) { sendKeys(tm, "e") m := getFinalModel(t, tm) - if m.CursorX() != 4 { - t.Errorf("m.CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -216,8 +216,8 @@ func TestMoveToWordEnd(t *testing.T) { sendKeys(tm, "e", "e") m := getFinalModel(t, tm) - if m.CursorX() != 6 { - t.Errorf("m.CursorX() = %d, want 6", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 6 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 6", m.ActiveWindow().Cursor.Col) } }) } @@ -229,8 +229,8 @@ func TestMoveBackwardWord(t *testing.T) { sendKeys(tm, "b") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("m.CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -240,8 +240,8 @@ func TestMoveBackwardWord(t *testing.T) { sendKeys(tm, "b") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("m.CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -251,8 +251,8 @@ func TestMoveBackwardWord(t *testing.T) { sendKeys(tm, "b", "b", "b") m := getFinalModel(t, tm) - if m.CursorX() != 6 { - t.Errorf("m.CursorX() = %d, want 6", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 6 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 6", m.ActiveWindow().Cursor.Col) } }) @@ -262,11 +262,11 @@ func TestMoveBackwardWord(t *testing.T) { sendKeys(tm, "b") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("m.CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 0", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 0 { - t.Errorf("m.CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("m.ActiveWindow().Cursor.Line = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -276,8 +276,8 @@ func TestMoveBackwardWord(t *testing.T) { sendKeys(tm, "b") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("m.CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -287,8 +287,8 @@ func TestMoveBackwardWord(t *testing.T) { sendKeys(tm, "b") m := getFinalModel(t, tm) - if m.CursorX() != 5 { - t.Errorf("m.CursorX() = %d, want 5", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 5 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 5", m.ActiveWindow().Cursor.Col) } }) @@ -298,8 +298,8 @@ func TestMoveBackwardWord(t *testing.T) { sendKeys(tm, "b") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("m.CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -309,8 +309,8 @@ func TestMoveBackwardWord(t *testing.T) { sendKeys(tm, "b") m := getFinalModel(t, tm) - if m.CursorX() != 5 { - t.Errorf("m.CursorX() = %d, want 5", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 5 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 5", m.ActiveWindow().Cursor.Col) } }) @@ -320,11 +320,11 @@ func TestMoveBackwardWord(t *testing.T) { sendKeys(tm, "b") m := getFinalModel(t, tm) - if m.CursorX() != 5 { - t.Errorf("m.CursorX() = %d, want 5", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 5 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 5", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 0 { - t.Errorf("m.CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("m.ActiveWindow().Cursor.Line = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -334,8 +334,8 @@ func TestMoveBackwardWord(t *testing.T) { sendKeys(tm, "b") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("m.CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("m.ActiveWindow().Cursor.Col = %d, want 0", m.ActiveWindow().Cursor.Col) } }) } @@ -363,8 +363,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // Should move to 'w' in "world" at index 6 - if m.CursorX() != 6 { - t.Errorf("CursorX() = %d, want 6", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 6 { + t.Errorf("CursorX() = %d, want 6", m.ActiveWindow().Cursor.Col) } }) @@ -375,8 +375,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // Should move to 't' in "three" at index 8 - if m.CursorX() != 8 { - t.Errorf("CursorX() = %d, want 8", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 8 { + t.Errorf("CursorX() = %d, want 8", m.ActiveWindow().Cursor.Col) } }) @@ -387,8 +387,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // Should move to 'f' in "four" at index 14 - if m.CursorX() != 14 { - t.Errorf("CursorX() = %d, want 14", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 14 { + t.Errorf("CursorX() = %d, want 14", m.ActiveWindow().Cursor.Col) } }) @@ -399,8 +399,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // From middle of "hello", should move to start of "world" - if m.CursorX() != 6 { - t.Errorf("CursorX() = %d, want 6", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 6 { + t.Errorf("CursorX() = %d, want 6", m.ActiveWindow().Cursor.Col) } }) @@ -411,8 +411,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // From 'o' in "hello", should move to 'w' in "world" - if m.CursorX() != 6 { - t.Errorf("CursorX() = %d, want 6", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 6 { + t.Errorf("CursorX() = %d, want 6", m.ActiveWindow().Cursor.Col) } }) @@ -423,8 +423,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // From space, should move to 'w' in "world" - if m.CursorX() != 6 { - t.Errorf("CursorX() = %d, want 6", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 6 { + t.Errorf("CursorX() = %d, want 6", m.ActiveWindow().Cursor.Col) } }) @@ -438,8 +438,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // Unlike 'w', 'W' treats "hello.world" as one WORD // Should skip to "next" at index 12 - if m.CursorX() != 12 { - t.Errorf("CursorX() = %d, want 12", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 12 { + t.Errorf("CursorX() = %d, want 12", m.ActiveWindow().Cursor.Col) } }) @@ -450,8 +450,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // "hello,world" is one WORD, should move to "next" - if m.CursorX() != 12 { - t.Errorf("CursorX() = %d, want 12", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 12 { + t.Errorf("CursorX() = %d, want 12", m.ActiveWindow().Cursor.Col) } }) @@ -462,8 +462,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // "hello...world!!!" is one WORD - if m.CursorX() != 17 { - t.Errorf("CursorX() = %d, want 17", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 17 { + t.Errorf("CursorX() = %d, want 17", m.ActiveWindow().Cursor.Col) } }) @@ -474,8 +474,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // "func(arg)" is one WORD - if m.CursorX() != 10 { - t.Errorf("CursorX() = %d, want 10", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 10 { + t.Errorf("CursorX() = %d, want 10", m.ActiveWindow().Cursor.Col) } }) @@ -486,8 +486,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // "a+=b" is one WORD - if m.CursorX() != 5 { - t.Errorf("CursorX() = %d, want 5", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 5 { + t.Errorf("CursorX() = %d, want 5", m.ActiveWindow().Cursor.Col) } }) @@ -498,8 +498,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // `"hello"` is one WORD - if m.CursorX() != 8 { - t.Errorf("CursorX() = %d, want 8", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 8 { + t.Errorf("CursorX() = %d, want 8", m.ActiveWindow().Cursor.Col) } }) @@ -510,8 +510,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // "hello_world" is one WORD (same behavior as w for underscores) - if m.CursorX() != 12 { - t.Errorf("CursorX() = %d, want 12", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 12 { + t.Errorf("CursorX() = %d, want 12", m.ActiveWindow().Cursor.Col) } }) @@ -522,8 +522,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // "..." is one WORD - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -534,8 +534,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // From '.' which is part of "hello.", should move to "world" - if m.CursorX() != 7 { - t.Errorf("CursorX() = %d, want 7", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 7 { + t.Errorf("CursorX() = %d, want 7", m.ActiveWindow().Cursor.Col) } }) @@ -547,11 +547,11 @@ func TestMoveForwardWORD(t *testing.T) { sendKeys(tm, "W") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want 1", m.ActiveWindow().Cursor.Line) } }) @@ -561,11 +561,11 @@ func TestMoveForwardWORD(t *testing.T) { sendKeys(tm, "W") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 2 { - t.Errorf("CursorY() = %d, want 2", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 2 { + t.Errorf("CursorY() = %d, want 2", m.ActiveWindow().Cursor.Line) } }) @@ -575,11 +575,11 @@ func TestMoveForwardWORD(t *testing.T) { sendKeys(tm, "W") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 4 { - t.Errorf("CursorY() = %d, want 4", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 4 { + t.Errorf("CursorY() = %d, want 4", m.ActiveWindow().Cursor.Line) } }) @@ -589,11 +589,11 @@ func TestMoveForwardWORD(t *testing.T) { sendKeys(tm, "W") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 2 { - t.Errorf("CursorY() = %d, want 2", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 2 { + t.Errorf("CursorY() = %d, want 2", m.ActiveWindow().Cursor.Line) } }) @@ -604,11 +604,11 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // From "third" on line 1, should move to "fourth" on line 2 - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 2 { - t.Errorf("CursorY() = %d, want 2", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 2 { + t.Errorf("CursorY() = %d, want 2", m.ActiveWindow().Cursor.Line) } }) @@ -621,8 +621,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // At last char, no more WORDs, should stay (or move to end) - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -633,8 +633,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // On "world", no next WORD, should go to end or stay - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -645,8 +645,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // Only one WORD, should move to end or stay - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -658,8 +658,8 @@ func TestMoveForwardWORD(t *testing.T) { sendKeys(tm, "W") m := getFinalModel(t, tm) - if m.CursorX() != 9 { - t.Errorf("CursorX() = %d, want 9", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 9 { + t.Errorf("CursorX() = %d, want 9", m.ActiveWindow().Cursor.Col) } }) @@ -670,8 +670,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // Tab is whitespace, "world" starts after tab - if m.CursorX() != 6 { - t.Errorf("CursorX() = %d, want 6", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 6 { + t.Errorf("CursorX() = %d, want 6", m.ActiveWindow().Cursor.Col) } }) @@ -683,8 +683,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // "hello \t world" - world starts at index 9 // h=0, e=1, l=2, l=3, o=4, space=5, tab=6, space=7, space=8, w=9 - if m.CursorX() != 9 { - t.Errorf("CursorX() = %d, want 9", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 9 { + t.Errorf("CursorX() = %d, want 9", m.ActiveWindow().Cursor.Col) } }) @@ -695,8 +695,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // From start (in whitespace), should move to "hello" at index 3 - if m.CursorX() != 3 { - t.Errorf("CursorX() = %d, want 3", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 3 { + t.Errorf("CursorX() = %d, want 3", m.ActiveWindow().Cursor.Col) } }) @@ -707,8 +707,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // From middle of leading whitespace, move to "hello" - if m.CursorX() != 3 { - t.Errorf("CursorX() = %d, want 3", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 3 { + t.Errorf("CursorX() = %d, want 3", m.ActiveWindow().Cursor.Col) } }) @@ -721,8 +721,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // Skip "one" and "two", land on "three" - if m.CursorX() != 8 { - t.Errorf("CursorX() = %d, want 8", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 8 { + t.Errorf("CursorX() = %d, want 8", m.ActiveWindow().Cursor.Col) } }) @@ -733,8 +733,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // Skip "one", "two", "three", land on "four" - if m.CursorX() != 14 { - t.Errorf("CursorX() = %d, want 14", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 14 { + t.Errorf("CursorX() = %d, want 14", m.ActiveWindow().Cursor.Col) } }) @@ -745,8 +745,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // Only 3 WORDs, should stop at/after last WORD - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -757,11 +757,11 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // Skip "one" and "two", land on "three" - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 2 { - t.Errorf("CursorY() = %d, want 2", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 2 { + t.Errorf("CursorY() = %d, want 2", m.ActiveWindow().Cursor.Line) } }) @@ -772,8 +772,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // Only 3 WORDs - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -794,14 +794,14 @@ func TestMoveForwardWORD(t *testing.T) { m2 := getFinalModel(t, tm2) // W should skip to "next", w should stop at "." - if m1.CursorX() == m2.CursorX() { + if m1.ActiveWindow().Cursor.Col == m2.ActiveWindow().Cursor.Col { t.Errorf("W and w should behave differently on punctuation") } - if m1.CursorX() != 12 { - t.Errorf("W: CursorX() = %d, want 12", m1.CursorX()) + if m1.ActiveWindow().Cursor.Col != 12 { + t.Errorf("W: CursorX() = %d, want 12", m1.ActiveWindow().Cursor.Col) } - if m2.CursorX() != 5 { - t.Errorf("w: CursorX() = %d, want 5", m2.CursorX()) + if m2.ActiveWindow().Cursor.Col != 5 { + t.Errorf("w: CursorX() = %d, want 5", m2.ActiveWindow().Cursor.Col) } }) @@ -813,11 +813,11 @@ func TestMoveForwardWORD(t *testing.T) { sendKeys(tm, "W") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -828,8 +828,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // Single char, no next WORD - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -839,8 +839,8 @@ func TestMoveForwardWORD(t *testing.T) { sendKeys(tm, "W") m := getFinalModel(t, tm) - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -851,11 +851,11 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // Should skip trailing whitespace and go to next line - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want 1", m.ActiveWindow().Cursor.Line) } }) @@ -866,8 +866,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // "func(a,b)" is one WORD, next is "{" - if m.CursorX() != 10 { - t.Errorf("CursorX() = %d, want 10", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 10 { + t.Errorf("CursorX() = %d, want 10", m.ActiveWindow().Cursor.Col) } }) @@ -878,8 +878,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // After "func(a,b)" and "{", should be on "return" - if m.CursorX() != 12 { - t.Errorf("CursorX() = %d, want 12", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 12 { + t.Errorf("CursorX() = %d, want 12", m.ActiveWindow().Cursor.Col) } }) @@ -890,8 +890,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // URL is one WORD, should move to "today" - if m.CursorX() != 35 { - t.Errorf("CursorX() = %d, want 35", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 35 { + t.Errorf("CursorX() = %d, want 35", m.ActiveWindow().Cursor.Col) } }) @@ -902,8 +902,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // Email is one WORD, should move to "now" - if m.CursorX() != 25 { - t.Errorf("CursorX() = %d, want 25", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 25 { + t.Errorf("CursorX() = %d, want 25", m.ActiveWindow().Cursor.Col) } }) @@ -914,8 +914,8 @@ func TestMoveForwardWORD(t *testing.T) { m := getFinalModel(t, tm) // Path is one WORD, should move to "now" - if m.CursorX() != 25 { - t.Errorf("CursorX() = %d, want 25", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 25 { + t.Errorf("CursorX() = %d, want 25", m.ActiveWindow().Cursor.Col) } }) } @@ -928,8 +928,8 @@ func TestMoveForwardWORDWithOperator(t *testing.T) { m := getFinalModel(t, tm) // Should delete "hello.world " (including trailing space) - if m.Line(0) != "next" { - t.Errorf("Line(0) = %q, want 'next'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "next" { + t.Errorf("Line(0) = %q, want 'next'", m.ActiveBuffer().Lines[0]) } }) @@ -946,11 +946,11 @@ func TestMoveForwardWORDWithOperator(t *testing.T) { sendKeys(tm2, "d", "w") m2 := getFinalModel(t, tm2) - if m1.Line(0) != "next" { - t.Errorf("dW: Line(0) = %q, want 'next'", m1.Line(0)) + if m1.ActiveBuffer().Lines[0] != "next" { + t.Errorf("dW: Line(0) = %q, want 'next'", m1.ActiveBuffer().Lines[0]) } - if m2.Line(0) != ".world next" { - t.Errorf("dw: Line(0) = %q, want '.world next'", m2.Line(0)) + if m2.ActiveBuffer().Lines[0] != ".world next" { + t.Errorf("dw: Line(0) = %q, want '.world next'", m2.ActiveBuffer().Lines[0]) } }) @@ -960,8 +960,8 @@ func TestMoveForwardWORDWithOperator(t *testing.T) { sendKeys(tm, "d", "2", "W") m := getFinalModel(t, tm) - if m.Line(0) != "three four" { - t.Errorf("Line(0) = %q, want 'three four'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "three four" { + t.Errorf("Line(0) = %q, want 'three four'", m.ActiveBuffer().Lines[0]) } }) @@ -1012,12 +1012,12 @@ func TestMoveForwardWORDInVisualMode(t *testing.T) { if m.Mode() != action.VisualMode { t.Errorf("Mode() = %v, want VisualMode", m.Mode()) } - if m.AnchorX() != 0 { - t.Errorf("AnchorX() = %d, want 0", m.AnchorX()) + if m.ActiveWindow().Anchor.Col != 0 { + t.Errorf("AnchorX() = %d, want 0", m.ActiveWindow().Anchor.Col) } // Should extend to start of "next" - if m.CursorX() != 12 { - t.Errorf("CursorX() = %d, want 12", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 12 { + t.Errorf("CursorX() = %d, want 12", m.ActiveWindow().Cursor.Col) } }) @@ -1028,8 +1028,8 @@ func TestMoveForwardWORDInVisualMode(t *testing.T) { m := getFinalModel(t, tm) // Visual selection from 0 to 12, delete "hello.world " - if m.Line(0) != "ext" { - t.Errorf("Line(0) = %q, want 'ext'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "ext" { + t.Errorf("Line(0) = %q, want 'ext'", m.ActiveBuffer().Lines[0]) } }) @@ -1039,12 +1039,12 @@ func TestMoveForwardWORDInVisualMode(t *testing.T) { sendKeys(tm, "v", "2", "W") m := getFinalModel(t, tm) - if m.AnchorX() != 0 { - t.Errorf("AnchorX() = %d, want 0", m.AnchorX()) + if m.ActiveWindow().Anchor.Col != 0 { + t.Errorf("AnchorX() = %d, want 0", m.ActiveWindow().Anchor.Col) } // Should extend to start of "three" - if m.CursorX() != 8 { - t.Errorf("CursorX() = %d, want 8", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 8 { + t.Errorf("CursorX() = %d, want 8", m.ActiveWindow().Cursor.Col) } }) @@ -1058,8 +1058,8 @@ func TestMoveForwardWORDInVisualMode(t *testing.T) { t.Errorf("Mode() = %v, want VisualLineMode", m.Mode()) } // W should still move cursor, but line mode selects whole lines - if m.CursorX() != 6 { - t.Errorf("CursorX() = %d, want 6", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 6 { + t.Errorf("CursorX() = %d, want 6", m.ActiveWindow().Cursor.Col) } }) } @@ -1083,8 +1083,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // "hello" ends at index 4 - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -1095,8 +1095,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // "world" ends at index 10 - if m.CursorX() != 10 { - t.Errorf("CursorX() = %d, want 10", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 10 { + t.Errorf("CursorX() = %d, want 10", m.ActiveWindow().Cursor.Col) } }) @@ -1107,8 +1107,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // "test" ends at index 15 - if m.CursorX() != 15 { - t.Errorf("CursorX() = %d, want 15", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 15 { + t.Errorf("CursorX() = %d, want 15", m.ActiveWindow().Cursor.Col) } }) @@ -1119,8 +1119,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // From index 2 in "hello", E goes to index 4 (end of "hello") - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -1131,8 +1131,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // From end of "hello", E goes to end of "world" (index 10) - if m.CursorX() != 10 { - t.Errorf("CursorX() = %d, want 10", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 10 { + t.Errorf("CursorX() = %d, want 10", m.ActiveWindow().Cursor.Col) } }) @@ -1143,8 +1143,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // From space, E goes to end of "world" (index 10) - if m.CursorX() != 10 { - t.Errorf("CursorX() = %d, want 10", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 10 { + t.Errorf("CursorX() = %d, want 10", m.ActiveWindow().Cursor.Col) } }) @@ -1159,8 +1159,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // E treats "hello.world" as one WORD, ends at 'd' (index 10) - if m.CursorX() != 10 { - t.Errorf("CursorX() = %d, want 10", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 10 { + t.Errorf("CursorX() = %d, want 10", m.ActiveWindow().Cursor.Col) } }) @@ -1172,8 +1172,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m1 := getFinalModel(t, tm1) // 'e' should stop at end of "hello" (index 4) - if m1.CursorX() != 4 { - t.Errorf("'e': CursorX() = %d, want 4", m1.CursorX()) + if m1.ActiveWindow().Cursor.Col != 4 { + t.Errorf("'e': CursorX() = %d, want 4", m1.ActiveWindow().Cursor.Col) } // Now test 'E' @@ -1182,8 +1182,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m2 := getFinalModel(t, tm2) // 'E' should go to end of "hello.world" (index 10) - if m2.CursorX() != 10 { - t.Errorf("'E': CursorX() = %d, want 10", m2.CursorX()) + if m2.ActiveWindow().Cursor.Col != 10 { + t.Errorf("'E': CursorX() = %d, want 10", m2.ActiveWindow().Cursor.Col) } }) @@ -1194,8 +1194,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // "foo,bar" ends at index 6 - if m.CursorX() != 6 { - t.Errorf("CursorX() = %d, want 6", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 6 { + t.Errorf("CursorX() = %d, want 6", m.ActiveWindow().Cursor.Col) } }) @@ -1206,8 +1206,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // "a...b...c" ends at index 8 - if m.CursorX() != 8 { - t.Errorf("CursorX() = %d, want 8", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 8 { + t.Errorf("CursorX() = %d, want 8", m.ActiveWindow().Cursor.Col) } }) @@ -1218,8 +1218,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // "func(arg)" ends at index 8 - if m.CursorX() != 8 { - t.Errorf("CursorX() = %d, want 8", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 8 { + t.Errorf("CursorX() = %d, want 8", m.ActiveWindow().Cursor.Col) } }) @@ -1230,8 +1230,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // "a+b*c" ends at index 4 - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -1242,8 +1242,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // `"hello"` ends at index 6 - if m.CursorX() != 6 { - t.Errorf("CursorX() = %d, want 6", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 6 { + t.Errorf("CursorX() = %d, want 6", m.ActiveWindow().Cursor.Col) } }) @@ -1254,8 +1254,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // "..." ends at index 2 - if m.CursorX() != 2 { - t.Errorf("CursorX() = %d, want 2", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 2 { + t.Errorf("CursorX() = %d, want 2", m.ActiveWindow().Cursor.Col) } }) @@ -1266,8 +1266,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // From '.', E goes to 'd' (index 10) - if m.CursorX() != 10 { - t.Errorf("CursorX() = %d, want 10", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 10 { + t.Errorf("CursorX() = %d, want 10", m.ActiveWindow().Cursor.Col) } }) @@ -1282,11 +1282,11 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // Should be at end of "world" on line 1, index 4 - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want 1", m.ActiveWindow().Cursor.Line) } - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -1298,11 +1298,11 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // First E: end of "hello" (0,4) // Second E: skips empty line, end of "world" (2,4) - if m.CursorY() != 2 { - t.Errorf("CursorY() = %d, want 2", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 2 { + t.Errorf("CursorY() = %d, want 2", m.ActiveWindow().Cursor.Line) } - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -1312,11 +1312,11 @@ func TestMoveForwardWORDEnd(t *testing.T) { sendKeys(tm, "E", "E") m := getFinalModel(t, tm) - if m.CursorY() != 2 { - t.Errorf("CursorY() = %d, want 2", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 2 { + t.Errorf("CursorY() = %d, want 2", m.ActiveWindow().Cursor.Line) } - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -1332,11 +1332,11 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // Should stay at end of "hello" (index 4) - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -1347,8 +1347,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // Should be at end of "world" (index 10) - if m.CursorX() != 10 { - t.Errorf("CursorX() = %d, want 10", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 10 { + t.Errorf("CursorX() = %d, want 10", m.ActiveWindow().Cursor.Col) } }) @@ -1359,8 +1359,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // Already at end, should stay at 0 - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -1375,8 +1375,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // "world" ends at index 13 - if m.CursorX() != 13 { - t.Errorf("CursorX() = %d, want 13", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 13 { + t.Errorf("CursorX() = %d, want 13", m.ActiveWindow().Cursor.Col) } }) @@ -1387,8 +1387,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // "world" ends at index 10 - if m.CursorX() != 10 { - t.Errorf("CursorX() = %d, want 10", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 10 { + t.Errorf("CursorX() = %d, want 10", m.ActiveWindow().Cursor.Col) } }) @@ -1399,8 +1399,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // From start (in whitespace), E goes to end of "hello" (index 7) - if m.CursorX() != 7 { - t.Errorf("CursorX() = %d, want 7", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 7 { + t.Errorf("CursorX() = %d, want 7", m.ActiveWindow().Cursor.Col) } }) @@ -1415,8 +1415,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // "two" ends at index 6 - if m.CursorX() != 6 { - t.Errorf("CursorX() = %d, want 6", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 6 { + t.Errorf("CursorX() = %d, want 6", m.ActiveWindow().Cursor.Col) } }) @@ -1427,8 +1427,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // "three" ends at index 12 - if m.CursorX() != 12 { - t.Errorf("CursorX() = %d, want 12", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 12 { + t.Errorf("CursorX() = %d, want 12", m.ActiveWindow().Cursor.Col) } }) @@ -1439,8 +1439,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // Only 2 WORDs, should stop at end of "two" (index 6) - if m.CursorX() != 6 { - t.Errorf("CursorX() = %d, want 6", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 6 { + t.Errorf("CursorX() = %d, want 6", m.ActiveWindow().Cursor.Col) } }) @@ -1452,11 +1452,11 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // First E: end of "hello" (0,4) // Second E: end of "world" (1,4) - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want 1", m.ActiveWindow().Cursor.Line) } - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -1471,8 +1471,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // Entire URL is one WORD, ends at index 23 - if m.CursorX() != 23 { - t.Errorf("CursorX() = %d, want 23", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 23 { + t.Errorf("CursorX() = %d, want 23", m.ActiveWindow().Cursor.Col) } }) @@ -1483,8 +1483,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // Entire email is one WORD, ends at index 15 - if m.CursorX() != 15 { - t.Errorf("CursorX() = %d, want 15", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 15 { + t.Errorf("CursorX() = %d, want 15", m.ActiveWindow().Cursor.Col) } }) @@ -1495,8 +1495,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // Entire path is one WORD, ends at index 18 - if m.CursorX() != 18 { - t.Errorf("CursorX() = %d, want 18", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 18 { + t.Errorf("CursorX() = %d, want 18", m.ActiveWindow().Cursor.Col) } }) @@ -1507,8 +1507,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // "foo.bar(baz)" ends at index 11 - if m.CursorX() != 11 { - t.Errorf("CursorX() = %d, want 11", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 11 { + t.Errorf("CursorX() = %d, want 11", m.ActiveWindow().Cursor.Col) } }) @@ -1519,8 +1519,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // Second WORD "next.thing" ends at index 22 - if m.CursorX() != 22 { - t.Errorf("CursorX() = %d, want 22", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 22 { + t.Errorf("CursorX() = %d, want 22", m.ActiveWindow().Cursor.Col) } }) @@ -1531,8 +1531,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // "arr[0]" ends at index 5 - if m.CursorX() != 5 { - t.Errorf("CursorX() = %d, want 5", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 5 { + t.Errorf("CursorX() = %d, want 5", m.ActiveWindow().Cursor.Col) } }) @@ -1543,8 +1543,8 @@ func TestMoveForwardWORDEnd(t *testing.T) { m := getFinalModel(t, tm) // Entire chain is one WORD, ends at index 19 - if m.CursorX() != 19 { - t.Errorf("CursorX() = %d, want 19", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 19 { + t.Errorf("CursorX() = %d, want 19", m.ActiveWindow().Cursor.Col) } }) } @@ -1557,8 +1557,8 @@ func TestMoveForwardWORDEndWithOperator(t *testing.T) { m := getFinalModel(t, tm) // Should delete "hello.world" leaving " next" - if m.Line(0) != " next" { - t.Errorf("Line(0) = %q, want ' next'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != " next" { + t.Errorf("Line(0) = %q, want ' next'", m.ActiveBuffer().Lines[0]) } }) @@ -1570,8 +1570,8 @@ func TestMoveForwardWORDEndWithOperator(t *testing.T) { m1 := getFinalModel(t, tm1) // 'de' should delete "hello" leaving ".world next" - if m1.Line(0) != ".world next" { - t.Errorf("'de': Line(0) = %q, want '.world next'", m1.Line(0)) + if m1.ActiveBuffer().Lines[0] != ".world next" { + t.Errorf("'de': Line(0) = %q, want '.world next'", m1.ActiveBuffer().Lines[0]) } // Now test 'dE' @@ -1580,8 +1580,8 @@ func TestMoveForwardWORDEndWithOperator(t *testing.T) { m2 := getFinalModel(t, tm2) // 'dE' should delete "hello.world" leaving " next" - if m2.Line(0) != " next" { - t.Errorf("'dE': Line(0) = %q, want ' next'", m2.Line(0)) + if m2.ActiveBuffer().Lines[0] != " next" { + t.Errorf("'dE': Line(0) = %q, want ' next'", m2.ActiveBuffer().Lines[0]) } }) @@ -1592,8 +1592,8 @@ func TestMoveForwardWORDEndWithOperator(t *testing.T) { m := getFinalModel(t, tm) // Should delete "one.a two.b" leaving " three" - if m.Line(0) != " three" { - t.Errorf("Line(0) = %q, want ' three'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != " three" { + t.Errorf("Line(0) = %q, want ' three'", m.ActiveBuffer().Lines[0]) } }) @@ -1641,8 +1641,8 @@ func TestMoveForwardWORDEndInVisualMode(t *testing.T) { t.Errorf("Mode() = %v, want VisualMode", m.Mode()) } // Cursor at end of "hello.world" (index 10) - if m.CursorX() != 10 { - t.Errorf("CursorX() = %d, want 10", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 10 { + t.Errorf("CursorX() = %d, want 10", m.ActiveWindow().Cursor.Col) } }) @@ -1653,8 +1653,8 @@ func TestMoveForwardWORDEndInVisualMode(t *testing.T) { m := getFinalModel(t, tm) // Should delete "hello.world" leaving " next" - if m.Line(0) != " next" { - t.Errorf("Line(0) = %q, want ' next'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != " next" { + t.Errorf("Line(0) = %q, want ' next'", m.ActiveBuffer().Lines[0]) } }) @@ -1665,8 +1665,8 @@ func TestMoveForwardWORDEndInVisualMode(t *testing.T) { m := getFinalModel(t, tm) // Cursor at end of "baz.qux" (index 14) - if m.CursorX() != 14 { - t.Errorf("CursorX() = %d, want 14", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 14 { + t.Errorf("CursorX() = %d, want 14", m.ActiveWindow().Cursor.Col) } }) @@ -1680,8 +1680,8 @@ func TestMoveForwardWORDEndInVisualMode(t *testing.T) { t.Errorf("Mode() = %v, want VisualLineMode", m.Mode()) } // Cursor at end of "hello.world" (index 10) - if m.CursorX() != 10 { - t.Errorf("CursorX() = %d, want 10", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 10 { + t.Errorf("CursorX() = %d, want 10", m.ActiveWindow().Cursor.Col) } }) } diff --git a/internal/editor/integration_operator_change_test.go b/internal/editor/integration_operator_change_test.go index 5ca86a0..1f113ed 100644 --- a/internal/editor/integration_operator_change_test.go +++ b/internal/editor/integration_operator_change_test.go @@ -22,15 +22,15 @@ func TestChangeLine(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } // First line should be empty (ready for insert) - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "world" { - t.Errorf("Line(1) = %q, want 'world'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "world" { + t.Errorf("Line(1) = %q, want 'world'", m.ActiveBuffer().Lines[1]) } }) @@ -45,14 +45,14 @@ func TestChangeLine(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "line one" { - t.Errorf("Line(0) = %q, want 'line one'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line one" { + t.Errorf("Line(0) = %q, want 'line one'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "" { - t.Errorf("Line(1) = %q, want ''", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "" { + t.Errorf("Line(1) = %q, want ''", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "line three" { - t.Errorf("Line(2) = %q, want 'line three'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "line three" { + t.Errorf("Line(2) = %q, want 'line three'", m.ActiveBuffer().Lines[2]) } }) @@ -67,11 +67,11 @@ func TestChangeLine(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "hello" { - t.Errorf("Line(0) = %q, want 'hello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello" { + t.Errorf("Line(0) = %q, want 'hello'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "" { - t.Errorf("Line(1) = %q, want ''", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "" { + t.Errorf("Line(1) = %q, want ''", m.ActiveBuffer().Lines[1]) } }) @@ -106,11 +106,11 @@ func TestChangeLine(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -123,11 +123,11 @@ func TestChangeLine(t *testing.T) { m := getFinalModel(t, tm) // Cursor should be at column 0 on the empty line - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) } @@ -145,14 +145,14 @@ func TestChangeLineWithCount(t *testing.T) { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } // Should have 3 lines: empty + line three + line four - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "line three" { - t.Errorf("Line(1) = %q, want 'line three'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line three" { + t.Errorf("Line(1) = %q, want 'line three'", m.ActiveBuffer().Lines[1]) } }) @@ -168,17 +168,17 @@ func TestChangeLineWithCount(t *testing.T) { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } // Should have 3 lines: one + empty + five - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "one" { - t.Errorf("Line(0) = %q, want 'one'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "one" { + t.Errorf("Line(0) = %q, want 'one'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "" { - t.Errorf("Line(1) = %q, want ''", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "" { + t.Errorf("Line(1) = %q, want ''", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "five" { - t.Errorf("Line(2) = %q, want 'five'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "five" { + t.Errorf("Line(2) = %q, want 'five'", m.ActiveBuffer().Lines[2]) } }) @@ -193,11 +193,11 @@ func TestChangeLineWithCount(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -235,8 +235,8 @@ func TestChangeWithHorizontalMotion(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "ello world" { - t.Errorf("Line(0) = %q, want 'ello world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "ello world" { + t.Errorf("Line(0) = %q, want 'ello world'", m.ActiveBuffer().Lines[0]) } }) @@ -251,8 +251,8 @@ func TestChangeWithHorizontalMotion(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "llo world" { - t.Errorf("Line(0) = %q, want 'llo world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "llo world" { + t.Errorf("Line(0) = %q, want 'llo world'", m.ActiveBuffer().Lines[0]) } }) @@ -267,8 +267,8 @@ func TestChangeWithHorizontalMotion(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "hell world" { - t.Errorf("Line(0) = %q, want 'hell world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hell world" { + t.Errorf("Line(0) = %q, want 'hell world'", m.ActiveBuffer().Lines[0]) } }) @@ -283,8 +283,8 @@ func TestChangeWithHorizontalMotion(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "hello " { - t.Errorf("Line(0) = %q, want 'hello '", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello " { + t.Errorf("Line(0) = %q, want 'hello '", m.ActiveBuffer().Lines[0]) } }) @@ -299,8 +299,8 @@ func TestChangeWithHorizontalMotion(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "world" { - t.Errorf("Line(0) = %q, want 'world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "world" { + t.Errorf("Line(0) = %q, want 'world'", m.ActiveBuffer().Lines[0]) } }) @@ -317,8 +317,8 @@ func TestChangeWithHorizontalMotion(t *testing.T) { } // ^ is exclusive motion, so position 8 (space) is not included // Delete positions 3-7 ("hello"), leaving " " + " world" = " world" - if m.Line(0) != " world" { - t.Errorf("Line(0) = %q, want ' world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != " world" { + t.Errorf("Line(0) = %q, want ' world'", m.ActiveBuffer().Lines[0]) } }) } @@ -339,8 +339,8 @@ func TestChangeWithWordMotion(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "world" { - t.Errorf("Line(0) = %q, want 'world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "world" { + t.Errorf("Line(0) = %q, want 'world'", m.ActiveBuffer().Lines[0]) } }) @@ -355,8 +355,8 @@ func TestChangeWithWordMotion(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "heworld" { - t.Errorf("Line(0) = %q, want 'heworld'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "heworld" { + t.Errorf("Line(0) = %q, want 'heworld'", m.ActiveBuffer().Lines[0]) } }) @@ -371,8 +371,8 @@ func TestChangeWithWordMotion(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != " world" { - t.Errorf("Line(0) = %q, want ' world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != " world" { + t.Errorf("Line(0) = %q, want ' world'", m.ActiveBuffer().Lines[0]) } }) @@ -387,8 +387,8 @@ func TestChangeWithWordMotion(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "world" { - t.Errorf("Line(0) = %q, want 'world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "world" { + t.Errorf("Line(0) = %q, want 'world'", m.ActiveBuffer().Lines[0]) } }) @@ -403,8 +403,8 @@ func TestChangeWithWordMotion(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "three four" { - t.Errorf("Line(0) = %q, want 'three four'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "three four" { + t.Errorf("Line(0) = %q, want 'three four'", m.ActiveBuffer().Lines[0]) } }) @@ -419,8 +419,8 @@ func TestChangeWithWordMotion(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "next" { - t.Errorf("Line(0) = %q, want 'next'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "next" { + t.Errorf("Line(0) = %q, want 'next'", m.ActiveBuffer().Lines[0]) } }) @@ -435,8 +435,8 @@ func TestChangeWithWordMotion(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != " next" { - t.Errorf("Line(0) = %q, want ' next'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != " next" { + t.Errorf("Line(0) = %q, want ' next'", m.ActiveBuffer().Lines[0]) } }) } @@ -458,14 +458,14 @@ func TestChangeWithVerticalMotion(t *testing.T) { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } // Should have empty line + line three - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "line three" { - t.Errorf("Line(1) = %q, want 'line three'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line three" { + t.Errorf("Line(1) = %q, want 'line three'", m.ActiveBuffer().Lines[1]) } }) @@ -481,14 +481,14 @@ func TestChangeWithVerticalMotion(t *testing.T) { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } // Should have empty line + line three - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "line three" { - t.Errorf("Line(1) = %q, want 'line three'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line three" { + t.Errorf("Line(1) = %q, want 'line three'", m.ActiveBuffer().Lines[1]) } }) @@ -504,14 +504,14 @@ func TestChangeWithVerticalMotion(t *testing.T) { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } // Should have empty + four + five - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "four" { - t.Errorf("Line(1) = %q, want 'four'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "four" { + t.Errorf("Line(1) = %q, want 'four'", m.ActiveBuffer().Lines[1]) } }) } @@ -533,11 +533,11 @@ func TestChangeWithJumpMotion(t *testing.T) { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } // All lines should be replaced with one empty line - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -553,11 +553,11 @@ func TestChangeWithJumpMotion(t *testing.T) { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } // All lines should be replaced with one empty line - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -573,14 +573,14 @@ func TestChangeWithJumpMotion(t *testing.T) { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } // Should have line one + empty - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line one" { - t.Errorf("Line(0) = %q, want 'line one'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line one" { + t.Errorf("Line(0) = %q, want 'line one'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "" { - t.Errorf("Line(1) = %q, want ''", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "" { + t.Errorf("Line(1) = %q, want ''", m.ActiveBuffer().Lines[1]) } }) } @@ -601,8 +601,8 @@ func TestChangeToEndOfLine(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "hello " { - t.Errorf("Line(0) = %q, want 'hello '", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello " { + t.Errorf("Line(0) = %q, want 'hello '", m.ActiveBuffer().Lines[0]) } }) @@ -617,8 +617,8 @@ func TestChangeToEndOfLine(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -634,8 +634,8 @@ func TestChangeToEndOfLine(t *testing.T) { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } // Should delete last char - if m.Line(0) != "hell" { - t.Errorf("Line(0) = %q, want 'hell'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hell" { + t.Errorf("Line(0) = %q, want 'hell'", m.ActiveBuffer().Lines[0]) } }) @@ -673,8 +673,8 @@ func TestSubstituteCharacter(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "ello" { - t.Errorf("Line(0) = %q, want 'ello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "ello" { + t.Errorf("Line(0) = %q, want 'ello'", m.ActiveBuffer().Lines[0]) } }) @@ -689,8 +689,8 @@ func TestSubstituteCharacter(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "llo" { - t.Errorf("Line(0) = %q, want 'llo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "llo" { + t.Errorf("Line(0) = %q, want 'llo'", m.ActiveBuffer().Lines[0]) } }) @@ -705,8 +705,8 @@ func TestSubstituteCharacter(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "hell" { - t.Errorf("Line(0) = %q, want 'hell'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hell" { + t.Errorf("Line(0) = %q, want 'hell'", m.ActiveBuffer().Lines[0]) } }) } @@ -727,8 +727,8 @@ func TestSubstituteLine(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -740,14 +740,14 @@ func TestSubstituteLine(t *testing.T) { sendKeys(tm, "S") m := getFinalModel(t, tm) - if m.Line(0) != "line one" { - t.Errorf("Line(0) = %q, want 'line one'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line one" { + t.Errorf("Line(0) = %q, want 'line one'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "" { - t.Errorf("Line(1) = %q, want ''", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "" { + t.Errorf("Line(1) = %q, want ''", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "line three" { - t.Errorf("Line(2) = %q, want 'line three'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "line three" { + t.Errorf("Line(2) = %q, want 'line three'", m.ActiveBuffer().Lines[2]) } }) @@ -763,14 +763,14 @@ func TestSubstituteLine(t *testing.T) { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } // Should have empty + three + four - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "three" { - t.Errorf("Line(1) = %q, want 'three'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "three" { + t.Errorf("Line(1) = %q, want 'three'", m.ActiveBuffer().Lines[1]) } }) } @@ -791,8 +791,8 @@ func TestVisualModeChange(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "ello world" { - t.Errorf("Line(0) = %q, want 'ello world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "ello world" { + t.Errorf("Line(0) = %q, want 'ello world'", m.ActiveBuffer().Lines[0]) } }) @@ -807,8 +807,8 @@ func TestVisualModeChange(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != " world" { - t.Errorf("Line(0) = %q, want ' world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != " world" { + t.Errorf("Line(0) = %q, want ' world'", m.ActiveBuffer().Lines[0]) } }) @@ -823,8 +823,8 @@ func TestVisualModeChange(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "hello " { - t.Errorf("Line(0) = %q, want 'hello '", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello " { + t.Errorf("Line(0) = %q, want 'hello '", m.ActiveBuffer().Lines[0]) } }) @@ -840,8 +840,8 @@ func TestVisualModeChange(t *testing.T) { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } // Should merge lines with selection removed - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } }) @@ -875,11 +875,11 @@ func TestVisualLineModeChange(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(1) != "" { - t.Errorf("Line(1) = %q, want ''", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "" { + t.Errorf("Line(1) = %q, want ''", m.ActiveBuffer().Lines[1]) } }) @@ -895,17 +895,17 @@ func TestVisualLineModeChange(t *testing.T) { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } // Should have: line one, empty, line four - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line one" { - t.Errorf("Line(0) = %q, want 'line one'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line one" { + t.Errorf("Line(0) = %q, want 'line one'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "" { - t.Errorf("Line(1) = %q, want ''", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "" { + t.Errorf("Line(1) = %q, want ''", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "line four" { - t.Errorf("Line(2) = %q, want 'line four'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "line four" { + t.Errorf("Line(2) = %q, want 'line four'", m.ActiveBuffer().Lines[2]) } }) @@ -946,8 +946,8 @@ func TestChangeEdgeCases(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -963,8 +963,8 @@ func TestChangeEdgeCases(t *testing.T) { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } // cw on last word should change to end of line - if m.Line(0) != "hello " { - t.Errorf("Line(0) = %q, want 'hello '", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello " { + t.Errorf("Line(0) = %q, want 'hello '", m.ActiveBuffer().Lines[0]) } }) @@ -979,8 +979,8 @@ func TestChangeEdgeCases(t *testing.T) { if m.Mode() != action.InsertMode { t.Errorf("Mode() = %v, want InsertMode", m.Mode()) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } }) diff --git a/internal/editor/integration_operator_delete_test.go b/internal/editor/integration_operator_delete_test.go index 000ce7c..7d7e9a3 100644 --- a/internal/editor/integration_operator_delete_test.go +++ b/internal/editor/integration_operator_delete_test.go @@ -15,17 +15,17 @@ func TestDeleteLine(t *testing.T) { sendKeys(tm, "d", "d") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want '1'", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want '1'", m.ActiveBuffer().LineCount()) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want '0'", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want '0'", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want '0'", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want '0'", m.ActiveWindow().Cursor.Line) } - if m.Line(0) != "world" { - t.Errorf("Line(0) = %s, want 'world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "world" { + t.Errorf("Line(0) = %s, want 'world'", m.ActiveBuffer().Lines[0]) } }) @@ -35,20 +35,20 @@ func TestDeleteLine(t *testing.T) { sendKeys(tm, "d", "d") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want '2'", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want '2'", m.ActiveBuffer().LineCount()) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want '0'", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want '0'", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want '1'", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want '1'", m.ActiveWindow().Cursor.Line) } - if m.Line(0) != "hello" { - t.Errorf("Line(0) = %s, want 'hello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello" { + t.Errorf("Line(0) = %s, want 'hello'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "testing" { - t.Errorf("Line(1) = %s, want 'testing'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "testing" { + t.Errorf("Line(1) = %s, want 'testing'", m.ActiveBuffer().Lines[1]) } }) @@ -58,17 +58,17 @@ func TestDeleteLine(t *testing.T) { sendKeys(tm, "d", "d") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want '1'", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want '1'", m.ActiveBuffer().LineCount()) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want '0'", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want '0'", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want '0'", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want '0'", m.ActiveWindow().Cursor.Line) } - if m.Line(0) != "hello" { - t.Errorf("Line(0) = %s, want 'hello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello" { + t.Errorf("Line(0) = %s, want 'hello'", m.ActiveBuffer().Lines[0]) } }) @@ -78,17 +78,17 @@ func TestDeleteLine(t *testing.T) { sendKeys(tm, "d", "d") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want '1'", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want '1'", m.ActiveBuffer().LineCount()) } - if m.CursorX() != 3 { - t.Errorf("CursorX() = %d, want '3'", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 3 { + t.Errorf("CursorX() = %d, want '3'", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want '0'", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want '0'", m.ActiveWindow().Cursor.Line) } - if m.Line(0) != "world" { - t.Errorf("Line(0) = %s, want 'world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "world" { + t.Errorf("Line(0) = %s, want 'world'", m.ActiveBuffer().Lines[0]) } }) @@ -98,21 +98,21 @@ func TestDeleteLine(t *testing.T) { sendKeys(tm, "3", "d", "d") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want '2'", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want '2'", m.ActiveBuffer().LineCount()) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want '0'", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want '0'", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want '1'", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want '1'", m.ActiveWindow().Cursor.Line) } - if m.Line(0) != "hello" { - t.Errorf("Line(0) = %s, want 'hello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello" { + t.Errorf("Line(0) = %s, want 'hello'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "another line" { - t.Errorf("Line(1) = %s, want 'another line'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "another line" { + t.Errorf("Line(1) = %s, want 'another line'", m.ActiveBuffer().Lines[1]) } }) @@ -122,17 +122,17 @@ func TestDeleteLine(t *testing.T) { sendKeys(tm, "d", "d") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want '1'", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want '1'", m.ActiveBuffer().LineCount()) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want '0'", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want '0'", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want '0'", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want '0'", m.ActiveWindow().Cursor.Line) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %s, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %s, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -142,17 +142,17 @@ func TestDeleteLine(t *testing.T) { sendKeys(tm, "d", "d") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want '1'", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want '1'", m.ActiveBuffer().LineCount()) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want '0'", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want '0'", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want '0'", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want '0'", m.ActiveWindow().Cursor.Line) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %s, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %s, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -162,8 +162,8 @@ func TestDeleteLine(t *testing.T) { sendKeys(tm, "d", "d") m := getFinalModel(t, tm) - if m.CursorX() != 2 { - t.Errorf("CursorX() = %d, want 2", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 2 { + t.Errorf("CursorX() = %d, want 2", m.ActiveWindow().Cursor.Col) } }) @@ -173,11 +173,11 @@ func TestDeleteLine(t *testing.T) { sendKeys(tm, "3", "d", "d") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want \"\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want \"\"", m.ActiveBuffer().Lines[0]) } }) @@ -187,14 +187,14 @@ func TestDeleteLine(t *testing.T) { sendKeys(tm, "3", "d", "d") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "hello" { - t.Errorf("Line(0) = %q, want \"hello\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello" { + t.Errorf("Line(0) = %q, want \"hello\"", m.ActiveBuffer().Lines[0]) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -207,11 +207,11 @@ func TestDeleteOperatorWithHorozontalMotion(t *testing.T) { sendKeys(tm, "d", "l") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want '0'", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want '0'", m.ActiveWindow().Cursor.Col) } - if m.Line(0) != "ello" { - t.Errorf("Line(0) = %s, want 'ello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "ello" { + t.Errorf("Line(0) = %s, want 'ello'", m.ActiveBuffer().Lines[0]) } }) @@ -221,11 +221,11 @@ func TestDeleteOperatorWithHorozontalMotion(t *testing.T) { sendKeys(tm, "d", "l") m := getFinalModel(t, tm) - if m.CursorX() != 2 { - t.Errorf("CursorX() = %d, want '2'", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 2 { + t.Errorf("CursorX() = %d, want '2'", m.ActiveWindow().Cursor.Col) } - if m.Line(0) != "helo" { - t.Errorf("Line(0) = %s, want 'helo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "helo" { + t.Errorf("Line(0) = %s, want 'helo'", m.ActiveBuffer().Lines[0]) } }) @@ -235,11 +235,11 @@ func TestDeleteOperatorWithHorozontalMotion(t *testing.T) { sendKeys(tm, "d", "l") m := getFinalModel(t, tm) - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want '4'", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want '4'", m.ActiveWindow().Cursor.Col) } - if m.Line(0) != "hell" { - t.Errorf("Line(0) = %s, want 'hell'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hell" { + t.Errorf("Line(0) = %s, want 'hell'", m.ActiveBuffer().Lines[0]) } }) @@ -249,11 +249,11 @@ func TestDeleteOperatorWithHorozontalMotion(t *testing.T) { sendKeys(tm, "d", "h") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want '0'", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want '0'", m.ActiveWindow().Cursor.Col) } - if m.Line(0) != "hello" { - t.Errorf("Line(0) = %s, want 'hello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello" { + t.Errorf("Line(0) = %s, want 'hello'", m.ActiveBuffer().Lines[0]) } }) @@ -264,11 +264,11 @@ func TestDeleteOperatorWithHorozontalMotion(t *testing.T) { m := getFinalModel(t, tm) // dh deletes char to the left (position 1, 'e'), cursor moves to that position - if m.CursorX() != 1 { - t.Errorf("CursorX() = %d, want 1", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 1 { + t.Errorf("CursorX() = %d, want 1", m.ActiveWindow().Cursor.Col) } - if m.Line(0) != "hllo" { - t.Errorf("Line(0) = %q, want 'hllo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hllo" { + t.Errorf("Line(0) = %q, want 'hllo'", m.ActiveBuffer().Lines[0]) } }) @@ -279,11 +279,11 @@ func TestDeleteOperatorWithHorozontalMotion(t *testing.T) { m := getFinalModel(t, tm) // dh deletes char to the left (position 3, 'l'), cursor moves to that position - if m.CursorX() != 3 { - t.Errorf("CursorX() = %d, want 3", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 3 { + t.Errorf("CursorX() = %d, want 3", m.ActiveWindow().Cursor.Col) } - if m.Line(0) != "helo" { - t.Errorf("Line(0) = %q, want 'helo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "helo" { + t.Errorf("Line(0) = %q, want 'helo'", m.ActiveBuffer().Lines[0]) } }) @@ -293,8 +293,8 @@ func TestDeleteOperatorWithHorozontalMotion(t *testing.T) { sendKeys(tm, "2", "d", "l") m := getFinalModel(t, tm) - if m.Line(0) != "llo" { - t.Errorf("Line(0) = %q, want 'llo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "llo" { + t.Errorf("Line(0) = %q, want 'llo'", m.ActiveBuffer().Lines[0]) } }) @@ -304,8 +304,8 @@ func TestDeleteOperatorWithHorozontalMotion(t *testing.T) { sendKeys(tm, "d", "2", "l") m := getFinalModel(t, tm) - if m.Line(0) != "llo" { - t.Errorf("Line(0) = %q, want 'llo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "llo" { + t.Errorf("Line(0) = %q, want 'llo'", m.ActiveBuffer().Lines[0]) } }) @@ -315,8 +315,8 @@ func TestDeleteOperatorWithHorozontalMotion(t *testing.T) { sendKeys(tm, "2", "d", "h") m := getFinalModel(t, tm) - if m.Line(0) != "heo" { - t.Errorf("Line(0) = %q, want 'heo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "heo" { + t.Errorf("Line(0) = %q, want 'heo'", m.ActiveBuffer().Lines[0]) } }) } @@ -328,17 +328,17 @@ func TestDeleteOperatorWithVerticalMotion(t *testing.T) { sendKeys(tm, "d", "j") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 1" { - t.Errorf("Line(0) = %q, want 'line 1'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 1" { + t.Errorf("Line(0) = %q, want 'line 1'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "line 4" { - t.Errorf("Line(1) = %q, want 'line 4'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line 4" { + t.Errorf("Line(1) = %q, want 'line 4'", m.ActiveBuffer().Lines[1]) } - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want 1", m.ActiveWindow().Cursor.Line) } }) @@ -348,14 +348,14 @@ func TestDeleteOperatorWithVerticalMotion(t *testing.T) { sendKeys(tm, "d", "j") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 3" { - t.Errorf("Line(0) = %q, want 'line 3'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 3" { + t.Errorf("Line(0) = %q, want 'line 3'", m.ActiveBuffer().Lines[0]) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -367,14 +367,14 @@ func TestDeleteOperatorWithVerticalMotion(t *testing.T) { sendKeys(tm, "d", "j") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 1" { - t.Errorf("Line(0) = %q, want 'line 1'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 1" { + t.Errorf("Line(0) = %q, want 'line 1'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "line 2" { - t.Errorf("Line(1) = %q, want 'line 2'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line 2" { + t.Errorf("Line(1) = %q, want 'line 2'", m.ActiveBuffer().Lines[1]) } }) @@ -384,14 +384,14 @@ func TestDeleteOperatorWithVerticalMotion(t *testing.T) { sendKeys(tm, "d", "2", "j") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 1" { - t.Errorf("Line(0) = %q, want 'line 1'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 1" { + t.Errorf("Line(0) = %q, want 'line 1'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "line 5" { - t.Errorf("Line(1) = %q, want 'line 5'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line 5" { + t.Errorf("Line(1) = %q, want 'line 5'", m.ActiveBuffer().Lines[1]) } }) @@ -401,14 +401,14 @@ func TestDeleteOperatorWithVerticalMotion(t *testing.T) { sendKeys(tm, "2", "d", "j") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 1" { - t.Errorf("Line(0) = %q, want 'line 1'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 1" { + t.Errorf("Line(0) = %q, want 'line 1'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "line 5" { - t.Errorf("Line(1) = %q, want 'line 5'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line 5" { + t.Errorf("Line(1) = %q, want 'line 5'", m.ActiveBuffer().Lines[1]) } }) @@ -418,17 +418,17 @@ func TestDeleteOperatorWithVerticalMotion(t *testing.T) { sendKeys(tm, "d", "k") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 1" { - t.Errorf("Line(0) = %q, want 'line 1'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 1" { + t.Errorf("Line(0) = %q, want 'line 1'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "line 4" { - t.Errorf("Line(1) = %q, want 'line 4'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line 4" { + t.Errorf("Line(1) = %q, want 'line 4'", m.ActiveBuffer().Lines[1]) } - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want 1", m.ActiveWindow().Cursor.Line) } }) @@ -440,14 +440,14 @@ func TestDeleteOperatorWithVerticalMotion(t *testing.T) { sendKeys(tm, "d", "k") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 2" { - t.Errorf("Line(0) = %q, want 'line 2'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 2" { + t.Errorf("Line(0) = %q, want 'line 2'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "line 3" { - t.Errorf("Line(1) = %q, want 'line 3'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line 3" { + t.Errorf("Line(1) = %q, want 'line 3'", m.ActiveBuffer().Lines[1]) } }) @@ -457,14 +457,14 @@ func TestDeleteOperatorWithVerticalMotion(t *testing.T) { sendKeys(tm, "d", "k") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 3" { - t.Errorf("Line(0) = %q, want 'line 3'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 3" { + t.Errorf("Line(0) = %q, want 'line 3'", m.ActiveBuffer().Lines[0]) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -474,14 +474,14 @@ func TestDeleteOperatorWithVerticalMotion(t *testing.T) { sendKeys(tm, "d", "2", "k") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 1" { - t.Errorf("Line(0) = %q, want 'line 1'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 1" { + t.Errorf("Line(0) = %q, want 'line 1'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "line 5" { - t.Errorf("Line(1) = %q, want 'line 5'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line 5" { + t.Errorf("Line(1) = %q, want 'line 5'", m.ActiveBuffer().Lines[1]) } }) @@ -491,14 +491,14 @@ func TestDeleteOperatorWithVerticalMotion(t *testing.T) { sendKeys(tm, "2", "d", "k") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 1" { - t.Errorf("Line(0) = %q, want 'line 1'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 1" { + t.Errorf("Line(0) = %q, want 'line 1'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "line 5" { - t.Errorf("Line(1) = %q, want 'line 5'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line 5" { + t.Errorf("Line(1) = %q, want 'line 5'", m.ActiveBuffer().Lines[1]) } }) @@ -509,11 +509,11 @@ func TestDeleteOperatorWithVerticalMotion(t *testing.T) { m := getFinalModel(t, tm) // Should delete from line 1 to end - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 1" { - t.Errorf("Line(0) = %q, want 'line 1'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 1" { + t.Errorf("Line(0) = %q, want 'line 1'", m.ActiveBuffer().Lines[0]) } }) @@ -524,11 +524,11 @@ func TestDeleteOperatorWithVerticalMotion(t *testing.T) { m := getFinalModel(t, tm) // Should delete from line 0 to line 1 - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 3" { - t.Errorf("Line(0) = %q, want 'line 3'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 3" { + t.Errorf("Line(0) = %q, want 'line 3'", m.ActiveBuffer().Lines[0]) } }) } @@ -541,11 +541,11 @@ func TestDeleteOperatorWithWordMotion(t *testing.T) { sendKeys(tm, "d", "w") m := getFinalModel(t, tm) - if m.Line(0) != "world" { - t.Errorf("Line(0) = %q, want \"world\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "world" { + t.Errorf("Line(0) = %q, want \"world\"", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -555,11 +555,11 @@ func TestDeleteOperatorWithWordMotion(t *testing.T) { sendKeys(tm, "d", "w") m := getFinalModel(t, tm) - if m.Line(0) != "heworld" { - t.Errorf("Line(0) = %q, want \"heworld\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "heworld" { + t.Errorf("Line(0) = %q, want \"heworld\"", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 2 { - t.Errorf("CursorX() = %d, want 2", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 2 { + t.Errorf("CursorX() = %d, want 2", m.ActiveWindow().Cursor.Col) } }) @@ -569,8 +569,8 @@ func TestDeleteOperatorWithWordMotion(t *testing.T) { sendKeys(tm, "d", "w") m := getFinalModel(t, tm) - if m.Line(0) != "hello " { - t.Errorf("Line(0) = %q, want \"hello \"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello " { + t.Errorf("Line(0) = %q, want \"hello \"", m.ActiveBuffer().Lines[0]) } }) @@ -580,8 +580,8 @@ func TestDeleteOperatorWithWordMotion(t *testing.T) { sendKeys(tm, "2", "d", "w") m := getFinalModel(t, tm) - if m.Line(0) != "three four" { - t.Errorf("Line(0) = %q, want \"three four\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "three four" { + t.Errorf("Line(0) = %q, want \"three four\"", m.ActiveBuffer().Lines[0]) } }) @@ -591,8 +591,8 @@ func TestDeleteOperatorWithWordMotion(t *testing.T) { sendKeys(tm, "d", "2", "w") m := getFinalModel(t, tm) - if m.Line(0) != "three four" { - t.Errorf("Line(0) = %q, want \"three four\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "three four" { + t.Errorf("Line(0) = %q, want \"three four\"", m.ActiveBuffer().Lines[0]) } }) @@ -603,8 +603,8 @@ func TestDeleteOperatorWithWordMotion(t *testing.T) { m := getFinalModel(t, tm) // 'w' motion stops at punctuation, so it should delete "hello" - if m.Line(0) != ", world" { - t.Errorf("Line(0) = %q, want \", world\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != ", world" { + t.Errorf("Line(0) = %q, want \", world\"", m.ActiveBuffer().Lines[0]) } }) @@ -616,11 +616,11 @@ func TestDeleteOperatorWithWordMotion(t *testing.T) { m := getFinalModel(t, tm) // 'e' is inclusive - deletes "hello" (cols 0-4 inclusive), leaves " world" - if m.Line(0) != " world" { - t.Errorf("Line(0) = %q, want \" world\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != " world" { + t.Errorf("Line(0) = %q, want \" world\"", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -631,8 +631,8 @@ func TestDeleteOperatorWithWordMotion(t *testing.T) { m := getFinalModel(t, tm) // From 'l' (col 2) to 'o' (col 4) inclusive → deletes "llo" - if m.Line(0) != "he world" { - t.Errorf("Line(0) = %q, want \"he world\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "he world" { + t.Errorf("Line(0) = %q, want \"he world\"", m.ActiveBuffer().Lines[0]) } }) @@ -643,8 +643,8 @@ func TestDeleteOperatorWithWordMotion(t *testing.T) { m := getFinalModel(t, tm) // From 'o' of "hello" (col 4) to 'd' of "world" (col 10) inclusive - if m.Line(0) != "hell" { - t.Errorf("Line(0) = %q, want \"hell\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hell" { + t.Errorf("Line(0) = %q, want \"hell\"", m.ActiveBuffer().Lines[0]) } }) @@ -655,8 +655,8 @@ func TestDeleteOperatorWithWordMotion(t *testing.T) { m := getFinalModel(t, tm) // Deletes "one" and " two" (to end of second word inclusive) - if m.Line(0) != " three four" { - t.Errorf("Line(0) = %q, want \" three four\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != " three four" { + t.Errorf("Line(0) = %q, want \" three four\"", m.ActiveBuffer().Lines[0]) } }) @@ -667,8 +667,8 @@ func TestDeleteOperatorWithWordMotion(t *testing.T) { sendKeys(tm, "d", "b") m := getFinalModel(t, tm) - if m.Line(0) != "hello world" { - t.Errorf("Line(0) = %q, want \"hello world\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello world" { + t.Errorf("Line(0) = %q, want \"hello world\"", m.ActiveBuffer().Lines[0]) } }) @@ -679,8 +679,8 @@ func TestDeleteOperatorWithWordMotion(t *testing.T) { m := getFinalModel(t, tm) // cursor at 'r' of "world", db should delete back to start of "world" - if m.Line(0) != "hello rld" { - t.Errorf("Line(0) = %q, want \"hello rld\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello rld" { + t.Errorf("Line(0) = %q, want \"hello rld\"", m.ActiveBuffer().Lines[0]) } }) @@ -691,8 +691,8 @@ func TestDeleteOperatorWithWordMotion(t *testing.T) { m := getFinalModel(t, tm) // cursor at 'w', db should delete "hello " back - if m.Line(0) != "world" { - t.Errorf("Line(0) = %q, want \"world\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "world" { + t.Errorf("Line(0) = %q, want \"world\"", m.ActiveBuffer().Lines[0]) } }) @@ -703,8 +703,8 @@ func TestDeleteOperatorWithWordMotion(t *testing.T) { m := getFinalModel(t, tm) // cursor at 'f' of "four", 2db should delete "two three " - if m.Line(0) != "one four" { - t.Errorf("Line(0) = %q, want \"one four\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "one four" { + t.Errorf("Line(0) = %q, want \"one four\"", m.ActiveBuffer().Lines[0]) } }) @@ -715,8 +715,8 @@ func TestDeleteOperatorWithWordMotion(t *testing.T) { m := getFinalModel(t, tm) // cursor at 'd' (last char), db should delete back to start of "world" - if m.Line(0) != "hello d" { - t.Errorf("Line(0) = %q, want \"hello d\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello d" { + t.Errorf("Line(0) = %q, want \"hello d\"", m.ActiveBuffer().Lines[0]) } }) } @@ -729,8 +729,8 @@ func TestDeleteOperatorWithLinePositionMotion(t *testing.T) { sendKeys(tm, "d", "0") m := getFinalModel(t, tm) - if m.Line(0) != "hello world" { - t.Errorf("Line(0) = %q, want \"hello world\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello world" { + t.Errorf("Line(0) = %q, want \"hello world\"", m.ActiveBuffer().Lines[0]) } }) @@ -740,11 +740,11 @@ func TestDeleteOperatorWithLinePositionMotion(t *testing.T) { sendKeys(tm, "d", "0") m := getFinalModel(t, tm) - if m.Line(0) != "world" { - t.Errorf("Line(0) = %q, want \"world\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "world" { + t.Errorf("Line(0) = %q, want \"world\"", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -754,8 +754,8 @@ func TestDeleteOperatorWithLinePositionMotion(t *testing.T) { sendKeys(tm, "d", "0") m := getFinalModel(t, tm) - if m.Line(0) != "d" { - t.Errorf("Line(0) = %q, want \"d\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "d" { + t.Errorf("Line(0) = %q, want \"d\"", m.ActiveBuffer().Lines[0]) } }) @@ -765,8 +765,8 @@ func TestDeleteOperatorWithLinePositionMotion(t *testing.T) { sendKeys(tm, "d", "0") m := getFinalModel(t, tm) - if m.Line(0) != "lo world" { - t.Errorf("Line(0) = %q, want \"lo world\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "lo world" { + t.Errorf("Line(0) = %q, want \"lo world\"", m.ActiveBuffer().Lines[0]) } }) @@ -777,8 +777,8 @@ func TestDeleteOperatorWithLinePositionMotion(t *testing.T) { sendKeys(tm, "d", "$") m := getFinalModel(t, tm) - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want \"\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want \"\"", m.ActiveBuffer().Lines[0]) } }) @@ -788,8 +788,8 @@ func TestDeleteOperatorWithLinePositionMotion(t *testing.T) { sendKeys(tm, "d", "$") m := getFinalModel(t, tm) - if m.Line(0) != "hello " { - t.Errorf("Line(0) = %q, want \"hello \"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello " { + t.Errorf("Line(0) = %q, want \"hello \"", m.ActiveBuffer().Lines[0]) } }) @@ -799,8 +799,8 @@ func TestDeleteOperatorWithLinePositionMotion(t *testing.T) { sendKeys(tm, "d", "$") m := getFinalModel(t, tm) - if m.Line(0) != "hello worl" { - t.Errorf("Line(0) = %q, want \"hello worl\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello worl" { + t.Errorf("Line(0) = %q, want \"hello worl\"", m.ActiveBuffer().Lines[0]) } }) @@ -810,14 +810,14 @@ func TestDeleteOperatorWithLinePositionMotion(t *testing.T) { sendKeys(tm, "d", "$") m := getFinalModel(t, tm) - if m.Line(0) != "hello " { - t.Errorf("Line(0) = %q, want \"hello \"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello " { + t.Errorf("Line(0) = %q, want \"hello \"", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "second line" { - t.Errorf("Line(1) = %q, want \"second line\"", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "second line" { + t.Errorf("Line(1) = %q, want \"second line\"", m.ActiveBuffer().Lines[1]) } - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } }) @@ -827,11 +827,11 @@ func TestDeleteOperatorWithLinePositionMotion(t *testing.T) { sendKeys(tm, "d", "$") m := getFinalModel(t, tm) - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want \"\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want \"\"", m.ActiveBuffer().Lines[0]) } - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } }) @@ -843,11 +843,11 @@ func TestDeleteOperatorWithLinePositionMotion(t *testing.T) { m := getFinalModel(t, tm) // From col 0 to first non-whitespace (col 3, 'h') - deletes leading spaces - if m.Line(0) != "hello world" { - t.Errorf("Line(0) = %q, want \"hello world\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello world" { + t.Errorf("Line(0) = %q, want \"hello world\"", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -858,11 +858,11 @@ func TestDeleteOperatorWithLinePositionMotion(t *testing.T) { m := getFinalModel(t, tm) // From col 1 to first non-whitespace (col 3, 'h') - deletes cols 1-2 - if m.Line(0) != " hello world" { - t.Errorf("Line(0) = %q, want \" hello world\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != " hello world" { + t.Errorf("Line(0) = %q, want \" hello world\"", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 1 { - t.Errorf("CursorX() = %d, want 1", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 1 { + t.Errorf("CursorX() = %d, want 1", m.ActiveWindow().Cursor.Col) } }) @@ -874,8 +874,8 @@ func TestDeleteOperatorWithLinePositionMotion(t *testing.T) { m := getFinalModel(t, tm) // From col 6 ('l') back to col 3 ('h') // Should delete "hel" leaving " lo world" - if m.Line(0) != " lo world" { - t.Errorf("Line(0) = %q, want \" lo world\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != " lo world" { + t.Errorf("Line(0) = %q, want \" lo world\"", m.ActiveBuffer().Lines[0]) } }) @@ -887,8 +887,8 @@ func TestDeleteOperatorWithLinePositionMotion(t *testing.T) { m := getFinalModel(t, tm) // From col 5 (' ') back to col 0 ('h') // Should delete "hello" leaving " world" - if m.Line(0) != " world" { - t.Errorf("Line(0) = %q, want \" world\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != " world" { + t.Errorf("Line(0) = %q, want \" world\"", m.ActiveBuffer().Lines[0]) } }) } @@ -900,14 +900,14 @@ func TestDeleteOperatorWithJumpMotion(t *testing.T) { sendKeys(tm, "d", "G") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 1" { - t.Errorf("Line(0) = %q, want 'line 1'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 1" { + t.Errorf("Line(0) = %q, want 'line 1'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "line 2" { - t.Errorf("Line(1) = %q, want 'line 2'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line 2" { + t.Errorf("Line(1) = %q, want 'line 2'", m.ActiveBuffer().Lines[1]) } }) @@ -917,11 +917,11 @@ func TestDeleteOperatorWithJumpMotion(t *testing.T) { sendKeys(tm, "d", "G") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -931,14 +931,14 @@ func TestDeleteOperatorWithJumpMotion(t *testing.T) { sendKeys(tm, "d", "G") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 1" { - t.Errorf("Line(0) = %q, want 'line 1'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 1" { + t.Errorf("Line(0) = %q, want 'line 1'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "line 2" { - t.Errorf("Line(1) = %q, want 'line 2'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line 2" { + t.Errorf("Line(1) = %q, want 'line 2'", m.ActiveBuffer().Lines[1]) } }) @@ -948,8 +948,8 @@ func TestDeleteOperatorWithJumpMotion(t *testing.T) { sendKeys(tm, "d", "G") m := getFinalModel(t, tm) - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -959,14 +959,14 @@ func TestDeleteOperatorWithJumpMotion(t *testing.T) { sendKeys(tm, "d", "g", "g") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 4" { - t.Errorf("Line(0) = %q, want 'line 4'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 4" { + t.Errorf("Line(0) = %q, want 'line 4'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "line 5" { - t.Errorf("Line(1) = %q, want 'line 5'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line 5" { + t.Errorf("Line(1) = %q, want 'line 5'", m.ActiveBuffer().Lines[1]) } }) @@ -976,11 +976,11 @@ func TestDeleteOperatorWithJumpMotion(t *testing.T) { sendKeys(tm, "d", "g", "g") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -990,14 +990,14 @@ func TestDeleteOperatorWithJumpMotion(t *testing.T) { sendKeys(tm, "d", "g", "g") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 2" { - t.Errorf("Line(0) = %q, want 'line 2'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 2" { + t.Errorf("Line(0) = %q, want 'line 2'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "line 3" { - t.Errorf("Line(1) = %q, want 'line 3'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line 3" { + t.Errorf("Line(1) = %q, want 'line 3'", m.ActiveBuffer().Lines[1]) } }) @@ -1007,8 +1007,8 @@ func TestDeleteOperatorWithJumpMotion(t *testing.T) { sendKeys(tm, "d", "g", "g") m := getFinalModel(t, tm) - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -1018,11 +1018,11 @@ func TestDeleteOperatorWithJumpMotion(t *testing.T) { sendKeys(tm, "d", "G") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -1032,11 +1032,11 @@ func TestDeleteOperatorWithJumpMotion(t *testing.T) { sendKeys(tm, "d", "g", "g") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -1047,8 +1047,8 @@ func TestDeleteOperatorWithJumpMotion(t *testing.T) { m := getFinalModel(t, tm) // Cursor was at col 10, but "short" only has 5 chars - if m.CursorX() > len("short") { - t.Errorf("CursorX() = %d, should be clamped to line length %d", m.CursorX(), len("short")) + if m.ActiveWindow().Cursor.Col > len("short") { + t.Errorf("CursorX() = %d, should be clamped to line length %d", m.ActiveWindow().Cursor.Col, len("short")) } }) } diff --git a/internal/editor/integration_paste_test.go b/internal/editor/integration_paste_test.go index 81d48ad..6ee44b9 100644 --- a/internal/editor/integration_paste_test.go +++ b/internal/editor/integration_paste_test.go @@ -16,17 +16,17 @@ func TestPasteLinewiseBasic(t *testing.T) { sendKeys(tm, "p") m := getFinalModel(t, tm) - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 1" { - t.Errorf("Line(0) = %q, want 'line 1'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 1" { + t.Errorf("Line(0) = %q, want 'line 1'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "inserted" { - t.Errorf("Line(1) = %q, want 'inserted'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "inserted" { + t.Errorf("Line(1) = %q, want 'inserted'", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "line 2" { - t.Errorf("Line(2) = %q, want 'line 2'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "line 2" { + t.Errorf("Line(2) = %q, want 'line 2'", m.ActiveBuffer().Lines[2]) } }) @@ -39,8 +39,8 @@ func TestPasteLinewiseBasic(t *testing.T) { sendKeys(tm, "p") m := getFinalModel(t, tm) - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want 1", m.ActiveWindow().Cursor.Line) } }) @@ -53,14 +53,14 @@ func TestPasteLinewiseBasic(t *testing.T) { sendKeys(tm, "p") m := getFinalModel(t, tm) - if m.LineCount() != 4 { - t.Errorf("LineCount() = %d, want 4", m.LineCount()) + if m.ActiveBuffer().LineCount() != 4 { + t.Errorf("LineCount() = %d, want 4", m.ActiveBuffer().LineCount()) } - if m.Line(2) != "inserted" { - t.Errorf("Line(2) = %q, want 'inserted'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "inserted" { + t.Errorf("Line(2) = %q, want 'inserted'", m.ActiveBuffer().Lines[2]) } - if m.CursorY() != 2 { - t.Errorf("CursorY() = %d, want 2", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 2 { + t.Errorf("CursorY() = %d, want 2", m.ActiveWindow().Cursor.Line) } }) @@ -73,11 +73,11 @@ func TestPasteLinewiseBasic(t *testing.T) { sendKeys(tm, "p") m := getFinalModel(t, tm) - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(2) != "inserted" { - t.Errorf("Line(2) = %q, want 'inserted'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "inserted" { + t.Errorf("Line(2) = %q, want 'inserted'", m.ActiveBuffer().Lines[2]) } }) } @@ -92,23 +92,23 @@ func TestPasteLinewiseMultipleLines(t *testing.T) { sendKeys(tm, "p") m := getFinalModel(t, tm) - if m.LineCount() != 5 { - t.Errorf("LineCount() = %d, want 5", m.LineCount()) + if m.ActiveBuffer().LineCount() != 5 { + t.Errorf("LineCount() = %d, want 5", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 1" { - t.Errorf("Line(0) = %q, want 'line 1'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 1" { + t.Errorf("Line(0) = %q, want 'line 1'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "first" { - t.Errorf("Line(1) = %q, want 'first'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "first" { + t.Errorf("Line(1) = %q, want 'first'", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "second" { - t.Errorf("Line(2) = %q, want 'second'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "second" { + t.Errorf("Line(2) = %q, want 'second'", m.ActiveBuffer().Lines[2]) } - if m.Line(3) != "third" { - t.Errorf("Line(3) = %q, want 'third'", m.Line(3)) + if m.ActiveBuffer().Lines[3] != "third" { + t.Errorf("Line(3) = %q, want 'third'", m.ActiveBuffer().Lines[3]) } - if m.Line(4) != "line 2" { - t.Errorf("Line(4) = %q, want 'line 2'", m.Line(4)) + if m.ActiveBuffer().Lines[4] != "line 2" { + t.Errorf("Line(4) = %q, want 'line 2'", m.ActiveBuffer().Lines[4]) } }) @@ -121,8 +121,8 @@ func TestPasteLinewiseMultipleLines(t *testing.T) { sendKeys(tm, "p") m := getFinalModel(t, tm) - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want 1", m.ActiveWindow().Cursor.Line) } }) } @@ -137,18 +137,18 @@ func TestPasteLinewiseWithCount(t *testing.T) { sendKeys(tm, "2", "p") m := getFinalModel(t, tm) - if m.LineCount() != 4 { - t.Errorf("LineCount() = %d, want 4", m.LineCount()) + if m.ActiveBuffer().LineCount() != 4 { + t.Errorf("LineCount() = %d, want 4", m.ActiveBuffer().LineCount()) } // Both "inserted" lines should appear after line 1 - if m.Line(1) != "inserted" { - t.Errorf("Line(1) = %q, want 'inserted'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "inserted" { + t.Errorf("Line(1) = %q, want 'inserted'", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "inserted" { - t.Errorf("Line(2) = %q, want 'inserted'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "inserted" { + t.Errorf("Line(2) = %q, want 'inserted'", m.ActiveBuffer().Lines[2]) } - if m.Line(3) != "line 2" { - t.Errorf("Line(3) = %q, want 'line 2'", m.Line(3)) + if m.ActiveBuffer().Lines[3] != "line 2" { + t.Errorf("Line(3) = %q, want 'line 2'", m.ActiveBuffer().Lines[3]) } }) @@ -161,12 +161,12 @@ func TestPasteLinewiseWithCount(t *testing.T) { sendKeys(tm, "3", "p") m := getFinalModel(t, tm) - if m.LineCount() != 4 { - t.Errorf("LineCount() = %d, want 4", m.LineCount()) + if m.ActiveBuffer().LineCount() != 4 { + t.Errorf("LineCount() = %d, want 4", m.ActiveBuffer().LineCount()) } for i := 1; i <= 3; i++ { - if m.Line(i) != "pasted" { - t.Errorf("Line(%d) = %q, want 'pasted'", i, m.Line(i)) + if m.ActiveBuffer().Lines[i] != "pasted" { + t.Errorf("Line(%d) = %q, want 'pasted'", i, m.ActiveBuffer().Lines[i]) } } }) @@ -181,23 +181,23 @@ func TestPasteLinewiseWithCount(t *testing.T) { m := getFinalModel(t, tm) // Should be: original, first, second, first, second - if m.LineCount() != 5 { - t.Errorf("LineCount() = %d, want 5", m.LineCount()) + if m.ActiveBuffer().LineCount() != 5 { + t.Errorf("LineCount() = %d, want 5", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "original" { - t.Errorf("Line(0) = %q, want 'original'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "original" { + t.Errorf("Line(0) = %q, want 'original'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "first" { - t.Errorf("Line(1) = %q, want 'first'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "first" { + t.Errorf("Line(1) = %q, want 'first'", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "second" { - t.Errorf("Line(2) = %q, want 'second'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "second" { + t.Errorf("Line(2) = %q, want 'second'", m.ActiveBuffer().Lines[2]) } - if m.Line(3) != "first" { - t.Errorf("Line(3) = %q, want 'first'", m.Line(3)) + if m.ActiveBuffer().Lines[3] != "first" { + t.Errorf("Line(3) = %q, want 'first'", m.ActiveBuffer().Lines[3]) } - if m.Line(4) != "second" { - t.Errorf("Line(4) = %q, want 'second'", m.Line(4)) + if m.ActiveBuffer().Lines[4] != "second" { + t.Errorf("Line(4) = %q, want 'second'", m.ActiveBuffer().Lines[4]) } }) @@ -210,8 +210,8 @@ func TestPasteLinewiseWithCount(t *testing.T) { sendKeys(tm, "3", "p") m := getFinalModel(t, tm) - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want 1", m.ActiveWindow().Cursor.Line) } }) } @@ -228,17 +228,17 @@ func TestPasteBeforeLinewiseBasic(t *testing.T) { sendKeys(tm, "P") m := getFinalModel(t, tm) - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 1" { - t.Errorf("Line(0) = %q, want 'line 1'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 1" { + t.Errorf("Line(0) = %q, want 'line 1'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "inserted" { - t.Errorf("Line(1) = %q, want 'inserted'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "inserted" { + t.Errorf("Line(1) = %q, want 'inserted'", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "line 2" { - t.Errorf("Line(2) = %q, want 'line 2'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "line 2" { + t.Errorf("Line(2) = %q, want 'line 2'", m.ActiveBuffer().Lines[2]) } }) @@ -251,8 +251,8 @@ func TestPasteBeforeLinewiseBasic(t *testing.T) { sendKeys(tm, "P") m := getFinalModel(t, tm) - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want 1", m.ActiveWindow().Cursor.Line) } }) @@ -265,17 +265,17 @@ func TestPasteBeforeLinewiseBasic(t *testing.T) { sendKeys(tm, "P") m := getFinalModel(t, tm) - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "inserted" { - t.Errorf("Line(0) = %q, want 'inserted'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "inserted" { + t.Errorf("Line(0) = %q, want 'inserted'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "line 1" { - t.Errorf("Line(1) = %q, want 'line 1'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line 1" { + t.Errorf("Line(1) = %q, want 'line 1'", m.ActiveBuffer().Lines[1]) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -288,14 +288,14 @@ func TestPasteBeforeLinewiseBasic(t *testing.T) { sendKeys(tm, "P") m := getFinalModel(t, tm) - if m.LineCount() != 4 { - t.Errorf("LineCount() = %d, want 4", m.LineCount()) + if m.ActiveBuffer().LineCount() != 4 { + t.Errorf("LineCount() = %d, want 4", m.ActiveBuffer().LineCount()) } - if m.Line(1) != "inserted" { - t.Errorf("Line(1) = %q, want 'inserted'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "inserted" { + t.Errorf("Line(1) = %q, want 'inserted'", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "line 2" { - t.Errorf("Line(2) = %q, want 'line 2'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "line 2" { + t.Errorf("Line(2) = %q, want 'line 2'", m.ActiveBuffer().Lines[2]) } }) } @@ -310,23 +310,23 @@ func TestPasteBeforeLinewiseMultipleLines(t *testing.T) { sendKeys(tm, "P") m := getFinalModel(t, tm) - if m.LineCount() != 5 { - t.Errorf("LineCount() = %d, want 5", m.LineCount()) + if m.ActiveBuffer().LineCount() != 5 { + t.Errorf("LineCount() = %d, want 5", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 1" { - t.Errorf("Line(0) = %q, want 'line 1'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 1" { + t.Errorf("Line(0) = %q, want 'line 1'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "first" { - t.Errorf("Line(1) = %q, want 'first'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "first" { + t.Errorf("Line(1) = %q, want 'first'", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "second" { - t.Errorf("Line(2) = %q, want 'second'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "second" { + t.Errorf("Line(2) = %q, want 'second'", m.ActiveBuffer().Lines[2]) } - if m.Line(3) != "third" { - t.Errorf("Line(3) = %q, want 'third'", m.Line(3)) + if m.ActiveBuffer().Lines[3] != "third" { + t.Errorf("Line(3) = %q, want 'third'", m.ActiveBuffer().Lines[3]) } - if m.Line(4) != "line 2" { - t.Errorf("Line(4) = %q, want 'line 2'", m.Line(4)) + if m.ActiveBuffer().Lines[4] != "line 2" { + t.Errorf("Line(4) = %q, want 'line 2'", m.ActiveBuffer().Lines[4]) } }) @@ -339,8 +339,8 @@ func TestPasteBeforeLinewiseMultipleLines(t *testing.T) { sendKeys(tm, "P") m := getFinalModel(t, tm) - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want 1", m.ActiveWindow().Cursor.Line) } }) } @@ -355,18 +355,18 @@ func TestPasteBeforeLinewiseWithCount(t *testing.T) { sendKeys(tm, "2", "P") m := getFinalModel(t, tm) - if m.LineCount() != 4 { - t.Errorf("LineCount() = %d, want 4", m.LineCount()) + if m.ActiveBuffer().LineCount() != 4 { + t.Errorf("LineCount() = %d, want 4", m.ActiveBuffer().LineCount()) } // Both "inserted" lines should appear before line 2 - if m.Line(1) != "inserted" { - t.Errorf("Line(1) = %q, want 'inserted'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "inserted" { + t.Errorf("Line(1) = %q, want 'inserted'", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "inserted" { - t.Errorf("Line(2) = %q, want 'inserted'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "inserted" { + t.Errorf("Line(2) = %q, want 'inserted'", m.ActiveBuffer().Lines[2]) } - if m.Line(3) != "line 2" { - t.Errorf("Line(3) = %q, want 'line 2'", m.Line(3)) + if m.ActiveBuffer().Lines[3] != "line 2" { + t.Errorf("Line(3) = %q, want 'line 2'", m.ActiveBuffer().Lines[3]) } }) @@ -379,16 +379,16 @@ func TestPasteBeforeLinewiseWithCount(t *testing.T) { sendKeys(tm, "3", "P") m := getFinalModel(t, tm) - if m.LineCount() != 4 { - t.Errorf("LineCount() = %d, want 4", m.LineCount()) + if m.ActiveBuffer().LineCount() != 4 { + t.Errorf("LineCount() = %d, want 4", m.ActiveBuffer().LineCount()) } for i := 0; i < 3; i++ { - if m.Line(i) != "pasted" { - t.Errorf("Line(%d) = %q, want 'pasted'", i, m.Line(i)) + if m.ActiveBuffer().Lines[i] != "pasted" { + t.Errorf("Line(%d) = %q, want 'pasted'", i, m.ActiveBuffer().Lines[i]) } } - if m.Line(3) != "original" { - t.Errorf("Line(3) = %q, want 'original'", m.Line(3)) + if m.ActiveBuffer().Lines[3] != "original" { + t.Errorf("Line(3) = %q, want 'original'", m.ActiveBuffer().Lines[3]) } }) @@ -402,23 +402,23 @@ func TestPasteBeforeLinewiseWithCount(t *testing.T) { m := getFinalModel(t, tm) // Should be: first, second, first, second, original - if m.LineCount() != 5 { - t.Errorf("LineCount() = %d, want 5", m.LineCount()) + if m.ActiveBuffer().LineCount() != 5 { + t.Errorf("LineCount() = %d, want 5", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "first" { - t.Errorf("Line(0) = %q, want 'first'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "first" { + t.Errorf("Line(0) = %q, want 'first'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "second" { - t.Errorf("Line(1) = %q, want 'second'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "second" { + t.Errorf("Line(1) = %q, want 'second'", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "first" { - t.Errorf("Line(2) = %q, want 'first'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "first" { + t.Errorf("Line(2) = %q, want 'first'", m.ActiveBuffer().Lines[2]) } - if m.Line(3) != "second" { - t.Errorf("Line(3) = %q, want 'second'", m.Line(3)) + if m.ActiveBuffer().Lines[3] != "second" { + t.Errorf("Line(3) = %q, want 'second'", m.ActiveBuffer().Lines[3]) } - if m.Line(4) != "original" { - t.Errorf("Line(4) = %q, want 'original'", m.Line(4)) + if m.ActiveBuffer().Lines[4] != "original" { + t.Errorf("Line(4) = %q, want 'original'", m.ActiveBuffer().Lines[4]) } }) @@ -431,8 +431,8 @@ func TestPasteBeforeLinewiseWithCount(t *testing.T) { sendKeys(tm, "3", "P") m := getFinalModel(t, tm) - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want 1", m.ActiveWindow().Cursor.Line) } }) } @@ -447,14 +447,14 @@ func TestPasteBeforeLinewiseEdgeCases(t *testing.T) { sendKeys(tm, "P") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "inserted" { - t.Errorf("Line(0) = %q, want 'inserted'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "inserted" { + t.Errorf("Line(0) = %q, want 'inserted'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "only line" { - t.Errorf("Line(1) = %q, want 'only line'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "only line" { + t.Errorf("Line(1) = %q, want 'only line'", m.ActiveBuffer().Lines[1]) } }) @@ -467,8 +467,8 @@ func TestPasteBeforeLinewiseEdgeCases(t *testing.T) { sendKeys(tm, "P") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } }) @@ -481,11 +481,11 @@ func TestPasteBeforeLinewiseEdgeCases(t *testing.T) { sendKeys(tm, "P") m := getFinalModel(t, tm) - if m.Line(0) != " indented" { - t.Errorf("Line(0) = %q, want ' indented'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != " indented" { + t.Errorf("Line(0) = %q, want ' indented'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "\ttabbed" { - t.Errorf("Line(1) = %q, want '\\ttabbed'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "\ttabbed" { + t.Errorf("Line(1) = %q, want '\\ttabbed'", m.ActiveBuffer().Lines[1]) } }) @@ -498,12 +498,12 @@ func TestPasteBeforeLinewiseEdgeCases(t *testing.T) { sendKeys(tm, "1", "0", "P") // 10P m := getFinalModel(t, tm) - if m.LineCount() != 11 { - t.Errorf("LineCount() = %d, want 11", m.LineCount()) + if m.ActiveBuffer().LineCount() != 11 { + t.Errorf("LineCount() = %d, want 11", m.ActiveBuffer().LineCount()) } // Original should be at the end - if m.Line(10) != "original" { - t.Errorf("Line(10) = %q, want 'original'", m.Line(10)) + if m.ActiveBuffer().Lines[10] != "original" { + t.Errorf("Line(10) = %q, want 'original'", m.ActiveBuffer().Lines[10]) } }) } @@ -518,14 +518,14 @@ func TestPasteLinewiseEdgeCases(t *testing.T) { sendKeys(tm, "p") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "only line" { - t.Errorf("Line(0) = %q, want 'only line'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "only line" { + t.Errorf("Line(0) = %q, want 'only line'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "inserted" { - t.Errorf("Line(1) = %q, want 'inserted'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "inserted" { + t.Errorf("Line(1) = %q, want 'inserted'", m.ActiveBuffer().Lines[1]) } }) @@ -538,8 +538,8 @@ func TestPasteLinewiseEdgeCases(t *testing.T) { sendKeys(tm, "p") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } }) @@ -552,11 +552,11 @@ func TestPasteLinewiseEdgeCases(t *testing.T) { sendKeys(tm, "p") m := getFinalModel(t, tm) - if m.Line(1) != " indented" { - t.Errorf("Line(1) = %q, want ' indented'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != " indented" { + t.Errorf("Line(1) = %q, want ' indented'", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "\ttabbed" { - t.Errorf("Line(2) = %q, want '\\ttabbed'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "\ttabbed" { + t.Errorf("Line(2) = %q, want '\\ttabbed'", m.ActiveBuffer().Lines[2]) } }) @@ -569,8 +569,8 @@ func TestPasteLinewiseEdgeCases(t *testing.T) { sendKeys(tm, "1", "0", "p") // 10p m := getFinalModel(t, tm) - if m.LineCount() != 11 { - t.Errorf("LineCount() = %d, want 11", m.LineCount()) + if m.ActiveBuffer().LineCount() != 11 { + t.Errorf("LineCount() = %d, want 11", m.ActiveBuffer().LineCount()) } }) } @@ -590,8 +590,8 @@ func TestPasteCharwiseBasic(t *testing.T) { m := getFinalModel(t, tm) // Should insert after 'o': "helloXYZ world" - if m.Line(0) != "helloXYZ world" { - t.Errorf("Line(0) = %q, want 'helloXYZ world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "helloXYZ world" { + t.Errorf("Line(0) = %q, want 'helloXYZ world'", m.ActiveBuffer().Lines[0]) } }) @@ -604,8 +604,8 @@ func TestPasteCharwiseBasic(t *testing.T) { sendKeys(tm, "p") m := getFinalModel(t, tm) - if m.Line(0) != "hXello" { - t.Errorf("Line(0) = %q, want 'hXello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hXello" { + t.Errorf("Line(0) = %q, want 'hXello'", m.ActiveBuffer().Lines[0]) } }) @@ -618,8 +618,8 @@ func TestPasteCharwiseBasic(t *testing.T) { sendKeys(tm, "p") m := getFinalModel(t, tm) - if m.Line(0) != "hello!" { - t.Errorf("Line(0) = %q, want 'hello!'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello!" { + t.Errorf("Line(0) = %q, want 'hello!'", m.ActiveBuffer().Lines[0]) } }) @@ -632,8 +632,8 @@ func TestPasteCharwiseBasic(t *testing.T) { sendKeys(tm, "p") m := getFinalModel(t, tm) - if m.Line(0) != "text" { - t.Errorf("Line(0) = %q, want 'text'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "text" { + t.Errorf("Line(0) = %q, want 'text'", m.ActiveBuffer().Lines[0]) } }) @@ -646,8 +646,8 @@ func TestPasteCharwiseBasic(t *testing.T) { sendKeys(tm, "p") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } }) } @@ -662,8 +662,8 @@ func TestPasteCharwiseWithCount(t *testing.T) { sendKeys(tm, "2", "p") m := getFinalModel(t, tm) - if m.Line(0) != "hXXello" { - t.Errorf("Line(0) = %q, want 'hXXello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hXXello" { + t.Errorf("Line(0) = %q, want 'hXXello'", m.ActiveBuffer().Lines[0]) } }) @@ -676,8 +676,8 @@ func TestPasteCharwiseWithCount(t *testing.T) { sendKeys(tm, "3", "p") m := getFinalModel(t, tm) - if m.Line(0) != "start--- end" { - t.Errorf("Line(0) = %q, want 'start--- end'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "start--- end" { + t.Errorf("Line(0) = %q, want 'start--- end'", m.ActiveBuffer().Lines[0]) } }) @@ -690,8 +690,8 @@ func TestPasteCharwiseWithCount(t *testing.T) { sendKeys(tm, "2", "p") m := getFinalModel(t, tm) - if m.Line(0) != "aXYXYb" { - t.Errorf("Line(0) = %q, want 'aXYXYb'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "aXYXYb" { + t.Errorf("Line(0) = %q, want 'aXYXYb'", m.ActiveBuffer().Lines[0]) } }) } @@ -707,8 +707,8 @@ func TestPasteCharwiseCursorPosition(t *testing.T) { m := getFinalModel(t, tm) // Cursor should be at position after pasted text - if m.CursorX() != 3 { - t.Errorf("CursorX() = %d, want 3", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 3 { + t.Errorf("CursorX() = %d, want 3", m.ActiveWindow().Cursor.Col) } }) @@ -721,8 +721,8 @@ func TestPasteCharwiseCursorPosition(t *testing.T) { sendKeys(tm, "p") m := getFinalModel(t, tm) - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want 1", m.ActiveWindow().Cursor.Line) } }) } @@ -742,8 +742,8 @@ func TestPasteBeforeCharwiseBasic(t *testing.T) { m := getFinalModel(t, tm) // Should insert before space: "helloXYZ world" - if m.Line(0) != "helloXYZ world" { - t.Errorf("Line(0) = %q, want 'helloXYZ world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "helloXYZ world" { + t.Errorf("Line(0) = %q, want 'helloXYZ world'", m.ActiveBuffer().Lines[0]) } }) @@ -756,8 +756,8 @@ func TestPasteBeforeCharwiseBasic(t *testing.T) { sendKeys(tm, "P") m := getFinalModel(t, tm) - if m.Line(0) != "Xhello" { - t.Errorf("Line(0) = %q, want 'Xhello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "Xhello" { + t.Errorf("Line(0) = %q, want 'Xhello'", m.ActiveBuffer().Lines[0]) } }) @@ -770,8 +770,8 @@ func TestPasteBeforeCharwiseBasic(t *testing.T) { sendKeys(tm, "P") m := getFinalModel(t, tm) - if m.Line(0) != "hellXo" { - t.Errorf("Line(0) = %q, want 'hellXo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hellXo" { + t.Errorf("Line(0) = %q, want 'hellXo'", m.ActiveBuffer().Lines[0]) } }) @@ -784,8 +784,8 @@ func TestPasteBeforeCharwiseBasic(t *testing.T) { sendKeys(tm, "P") m := getFinalModel(t, tm) - if m.Line(0) != "text" { - t.Errorf("Line(0) = %q, want 'text'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "text" { + t.Errorf("Line(0) = %q, want 'text'", m.ActiveBuffer().Lines[0]) } }) } @@ -800,8 +800,8 @@ func TestPasteBeforeCharwiseWithCount(t *testing.T) { sendKeys(tm, "2", "P") m := getFinalModel(t, tm) - if m.Line(0) != "heXXllo" { - t.Errorf("Line(0) = %q, want 'heXXllo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "heXXllo" { + t.Errorf("Line(0) = %q, want 'heXXllo'", m.ActiveBuffer().Lines[0]) } }) @@ -814,8 +814,8 @@ func TestPasteBeforeCharwiseWithCount(t *testing.T) { sendKeys(tm, "3", "P") m := getFinalModel(t, tm) - if m.Line(0) != "a---b" { - t.Errorf("Line(0) = %q, want 'a---b'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "a---b" { + t.Errorf("Line(0) = %q, want 'a---b'", m.ActiveBuffer().Lines[0]) } }) } @@ -835,8 +835,8 @@ func TestPasteCharwiseMultiLine(t *testing.T) { m := getFinalModel(t, tm) // Current implementation errors - line should be unchanged - if m.Line(0) != "hello" { - t.Errorf("Line(0) = %q, want 'hello' (unchanged due to error)", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello" { + t.Errorf("Line(0) = %q, want 'hello' (unchanged due to error)", m.ActiveBuffer().Lines[0]) } }) @@ -850,8 +850,8 @@ func TestPasteCharwiseMultiLine(t *testing.T) { m := getFinalModel(t, tm) // Current implementation errors - line should be unchanged - if m.Line(0) != "hello" { - t.Errorf("Line(0) = %q, want 'hello' (unchanged due to error)", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello" { + t.Errorf("Line(0) = %q, want 'hello' (unchanged due to error)", m.ActiveBuffer().Lines[0]) } }) } @@ -871,8 +871,8 @@ func TestPasteBlockwiseBasic(t *testing.T) { m := getFinalModel(t, tm) // Current implementation errors - lines should be unchanged - if m.Line(0) != "aaaa" { - t.Errorf("Line(0) = %q, want 'aaaa' (unchanged due to error)", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "aaaa" { + t.Errorf("Line(0) = %q, want 'aaaa' (unchanged due to error)", m.ActiveBuffer().Lines[0]) } }) @@ -886,8 +886,8 @@ func TestPasteBlockwiseBasic(t *testing.T) { m := getFinalModel(t, tm) // Current implementation errors - lines should be unchanged - if m.Line(0) != "aaaa" { - t.Errorf("Line(0) = %q, want 'aaaa' (unchanged due to error)", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "aaaa" { + t.Errorf("Line(0) = %q, want 'aaaa' (unchanged due to error)", m.ActiveBuffer().Lines[0]) } }) } @@ -906,8 +906,8 @@ func TestPasteCharwiseEdgeCases(t *testing.T) { sendKeys(tm, "p") m := getFinalModel(t, tm) - if m.Line(0) != "hello" { - t.Errorf("Line(0) = %q, want 'hello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello" { + t.Errorf("Line(0) = %q, want 'hello'", m.ActiveBuffer().Lines[0]) } }) @@ -920,8 +920,8 @@ func TestPasteCharwiseEdgeCases(t *testing.T) { sendKeys(tm, "p") m := getFinalModel(t, tm) - if m.Line(0) != "hello" { - t.Errorf("Line(0) = %q, want 'hello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello" { + t.Errorf("Line(0) = %q, want 'hello'", m.ActiveBuffer().Lines[0]) } }) @@ -934,8 +934,8 @@ func TestPasteCharwiseEdgeCases(t *testing.T) { sendKeys(tm, "p") m := getFinalModel(t, tm) - if m.Line(0) != "a\tb" { - t.Errorf("Line(0) = %q, want 'a\\tb'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "a\tb" { + t.Errorf("Line(0) = %q, want 'a\\tb'", m.ActiveBuffer().Lines[0]) } }) @@ -948,8 +948,8 @@ func TestPasteCharwiseEdgeCases(t *testing.T) { sendKeys(tm, "p") m := getFinalModel(t, tm) - if m.Line(0) != "a b" { - t.Errorf("Line(0) = %q, want 'a b'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "a b" { + t.Errorf("Line(0) = %q, want 'a b'", m.ActiveBuffer().Lines[0]) } }) @@ -962,8 +962,8 @@ func TestPasteCharwiseEdgeCases(t *testing.T) { sendKeys(tm, "p") m := getFinalModel(t, tm) - if m.Line(0) != " X " { - t.Errorf("Line(0) = %q, want ' X '", m.Line(0)) + if m.ActiveBuffer().Lines[0] != " X " { + t.Errorf("Line(0) = %q, want ' X '", m.ActiveBuffer().Lines[0]) } }) @@ -976,8 +976,8 @@ func TestPasteCharwiseEdgeCases(t *testing.T) { sendKeys(tm, "P") m := getFinalModel(t, tm) - if m.Line(0) != "hello" { - t.Errorf("Line(0) = %q, want 'hello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello" { + t.Errorf("Line(0) = %q, want 'hello'", m.ActiveBuffer().Lines[0]) } }) @@ -990,8 +990,8 @@ func TestPasteCharwiseEdgeCases(t *testing.T) { sendKeys(tm, "1", "0", "p") // 10p m := getFinalModel(t, tm) - if m.Line(0) != "aXXXXXXXXXXb" { - t.Errorf("Line(0) = %q, want 'aXXXXXXXXXXb'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "aXXXXXXXXXXb" { + t.Errorf("Line(0) = %q, want 'aXXXXXXXXXXb'", m.ActiveBuffer().Lines[0]) } }) } @@ -1011,8 +1011,8 @@ func TestYankThenPasteCharwise(t *testing.T) { sendKeys(tm, "p") // paste m := getFinalModel(t, tm) - if m.Line(0) != "hello worldhello " { - t.Errorf("Line(0) = %q, want 'hello worldhello '", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello worldhello " { + t.Errorf("Line(0) = %q, want 'hello worldhello '", m.ActiveBuffer().Lines[0]) } }) @@ -1026,8 +1026,8 @@ func TestYankThenPasteCharwise(t *testing.T) { sendKeys(tm, "p") // paste m := getFinalModel(t, tm) - if m.Line(0) != "hello worldhello" { - t.Errorf("Line(0) = %q, want 'hello worldhello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello worldhello" { + t.Errorf("Line(0) = %q, want 'hello worldhello'", m.ActiveBuffer().Lines[0]) } }) @@ -1041,8 +1041,8 @@ func TestYankThenPasteCharwise(t *testing.T) { sendKeys(tm, "p") // paste m := getFinalModel(t, tm) - if m.Line(0) != "hello worldhel" { - t.Errorf("Line(0) = %q, want 'hello worldhel'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello worldhel" { + t.Errorf("Line(0) = %q, want 'hello worldhel'", m.ActiveBuffer().Lines[0]) } }) } @@ -1067,8 +1067,8 @@ func TestVisualModePasteCharwise(t *testing.T) { sendKeys(tm, "v", "l", "l", "l", "l", "p") // select "hello", paste m := getFinalModel(t, tm) - if m.Line(0) != "REPLACED world" { - t.Errorf("Line(0) = %q, want 'REPLACED world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "REPLACED world" { + t.Errorf("Line(0) = %q, want 'REPLACED world'", m.ActiveBuffer().Lines[0]) } }) @@ -1081,8 +1081,8 @@ func TestVisualModePasteCharwise(t *testing.T) { sendKeys(tm, "v", "p") // select "h", paste m := getFinalModel(t, tm) - if m.Line(0) != "Xello world" { - t.Errorf("Line(0) = %q, want 'Xello world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "Xello world" { + t.Errorf("Line(0) = %q, want 'Xello world'", m.ActiveBuffer().Lines[0]) } }) @@ -1095,8 +1095,8 @@ func TestVisualModePasteCharwise(t *testing.T) { sendKeys(tm, "v", "e", "p") // select "world", paste m := getFinalModel(t, tm) - if m.Line(0) != "hello EARTH goodbye" { - t.Errorf("Line(0) = %q, want 'hello EARTH goodbye'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello EARTH goodbye" { + t.Errorf("Line(0) = %q, want 'hello EARTH goodbye'", m.ActiveBuffer().Lines[0]) } }) @@ -1109,8 +1109,8 @@ func TestVisualModePasteCharwise(t *testing.T) { sendKeys(tm, "v", "$", "p") // select "world", paste m := getFinalModel(t, tm) - if m.Line(0) != "hello universe" { - t.Errorf("Line(0) = %q, want 'hello universe'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello universe" { + t.Errorf("Line(0) = %q, want 'hello universe'", m.ActiveBuffer().Lines[0]) } }) @@ -1123,8 +1123,8 @@ func TestVisualModePasteCharwise(t *testing.T) { sendKeys(tm, "v", "l", "l", "l", "l", "p") // select "hello", paste empty m := getFinalModel(t, tm) - if m.Line(0) != " world" { - t.Errorf("Line(0) = %q, want ' world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != " world" { + t.Errorf("Line(0) = %q, want ' world'", m.ActiveBuffer().Lines[0]) } }) @@ -1144,11 +1144,11 @@ func TestVisualModePasteCharwise(t *testing.T) { m := getFinalModel(t, tm) // Should join: "line " + "REPLACED" + "two" - if m.Line(0) != "line REPLACEDtwo" { - t.Errorf("Line(0) = %q, want 'line REPLACEDtwo'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line REPLACEDtwo" { + t.Errorf("Line(0) = %q, want 'line REPLACEDtwo'", m.ActiveBuffer().Lines[0]) } - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } }) @@ -1167,8 +1167,8 @@ func TestVisualModePasteCharwise(t *testing.T) { m := getFinalModel(t, tm) // Cursor should be at start of pasted content (or end, depending on impl) // In Vim, cursor goes to last char of pasted text - if m.CursorX() != 10 { - t.Errorf("CursorX() = %d, want 10", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 10 { + t.Errorf("CursorX() = %d, want 10", m.ActiveWindow().Cursor.Col) } }) @@ -1200,8 +1200,8 @@ func TestVisualModePasteCharwise(t *testing.T) { m := getFinalModel(t, tm) // Linewise register content is pasted inline replacing the selection - if m.Line(0) != "NEW LINE world" { - t.Errorf("Line(0) = %q, want 'NEW LINE world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "NEW LINE world" { + t.Errorf("Line(0) = %q, want 'NEW LINE world'", m.ActiveBuffer().Lines[0]) } }) } @@ -1220,11 +1220,11 @@ func TestVisualLinePaste(t *testing.T) { sendKeys(tm, "V", "p") // select line two, paste m := getFinalModel(t, tm) - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(1) != "REPLACED" { - t.Errorf("Line(1) = %q, want 'REPLACED'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "REPLACED" { + t.Errorf("Line(1) = %q, want 'REPLACED'", m.ActiveBuffer().Lines[1]) } }) @@ -1237,11 +1237,11 @@ func TestVisualLinePaste(t *testing.T) { sendKeys(tm, "V", "p") // select line two, paste m := getFinalModel(t, tm) - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(1) != "NEW LINE" { - t.Errorf("Line(1) = %q, want 'NEW LINE'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "NEW LINE" { + t.Errorf("Line(1) = %q, want 'NEW LINE'", m.ActiveBuffer().Lines[1]) } }) @@ -1254,17 +1254,17 @@ func TestVisualLinePaste(t *testing.T) { sendKeys(tm, "V", "j", "p") // select lines two and three, paste m := getFinalModel(t, tm) - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line one" { - t.Errorf("Line(0) = %q, want 'line one'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line one" { + t.Errorf("Line(0) = %q, want 'line one'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "REPLACED" { - t.Errorf("Line(1) = %q, want 'REPLACED'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "REPLACED" { + t.Errorf("Line(1) = %q, want 'REPLACED'", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "line four" { - t.Errorf("Line(2) = %q, want 'line four'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "line four" { + t.Errorf("Line(2) = %q, want 'line four'", m.ActiveBuffer().Lines[2]) } }) @@ -1277,20 +1277,20 @@ func TestVisualLinePaste(t *testing.T) { sendKeys(tm, "V", "j", "p") // select lines two and three, paste two lines m := getFinalModel(t, tm) - if m.LineCount() != 4 { - t.Errorf("LineCount() = %d, want 4", m.LineCount()) + if m.ActiveBuffer().LineCount() != 4 { + t.Errorf("LineCount() = %d, want 4", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line one" { - t.Errorf("Line(0) = %q, want 'line one'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line one" { + t.Errorf("Line(0) = %q, want 'line one'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "NEW A" { - t.Errorf("Line(1) = %q, want 'NEW A'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "NEW A" { + t.Errorf("Line(1) = %q, want 'NEW A'", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "NEW B" { - t.Errorf("Line(2) = %q, want 'NEW B'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "NEW B" { + t.Errorf("Line(2) = %q, want 'NEW B'", m.ActiveBuffer().Lines[2]) } - if m.Line(3) != "line four" { - t.Errorf("Line(3) = %q, want 'line four'", m.Line(3)) + if m.ActiveBuffer().Lines[3] != "line four" { + t.Errorf("Line(3) = %q, want 'line four'", m.ActiveBuffer().Lines[3]) } }) @@ -1303,14 +1303,14 @@ func TestVisualLinePaste(t *testing.T) { sendKeys(tm, "V", "p") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "FIRST" { - t.Errorf("Line(0) = %q, want 'FIRST'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "FIRST" { + t.Errorf("Line(0) = %q, want 'FIRST'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "line two" { - t.Errorf("Line(1) = %q, want 'line two'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line two" { + t.Errorf("Line(1) = %q, want 'line two'", m.ActiveBuffer().Lines[1]) } }) @@ -1323,14 +1323,14 @@ func TestVisualLinePaste(t *testing.T) { sendKeys(tm, "V", "p") m := getFinalModel(t, tm) - if m.LineCount() != 2 { - t.Errorf("LineCount() = %d, want 2", m.LineCount()) + if m.ActiveBuffer().LineCount() != 2 { + t.Errorf("LineCount() = %d, want 2", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line one" { - t.Errorf("Line(0) = %q, want 'line one'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line one" { + t.Errorf("Line(0) = %q, want 'line one'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "LAST" { - t.Errorf("Line(1) = %q, want 'LAST'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "LAST" { + t.Errorf("Line(1) = %q, want 'LAST'", m.ActiveBuffer().Lines[1]) } }) @@ -1409,8 +1409,8 @@ func TestVisualPasteEdgeCases(t *testing.T) { sendKeys(tm, "v", "p") m := getFinalModel(t, tm) - if m.Line(0) != "NEW" { - t.Errorf("Line(0) = %q, want 'NEW'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "NEW" { + t.Errorf("Line(0) = %q, want 'NEW'", m.ActiveBuffer().Lines[0]) } }) @@ -1423,8 +1423,8 @@ func TestVisualPasteEdgeCases(t *testing.T) { sendKeys(tm, "v", "$", "p") // select entire "hello" m := getFinalModel(t, tm) - if m.Line(0) != "REPLACED" { - t.Errorf("Line(0) = %q, want 'REPLACED'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "REPLACED" { + t.Errorf("Line(0) = %q, want 'REPLACED'", m.ActiveBuffer().Lines[0]) } }) @@ -1437,8 +1437,8 @@ func TestVisualPasteEdgeCases(t *testing.T) { sendKeys(tm, "v", "h", "h", "h", "h", "h", "p") // select backwards "hello ", paste m := getFinalModel(t, tm) - if m.Line(0) != "Xworld" { - t.Errorf("Line(0) = %q, want 'Xworld'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "Xworld" { + t.Errorf("Line(0) = %q, want 'Xworld'", m.ActiveBuffer().Lines[0]) } }) @@ -1451,8 +1451,8 @@ func TestVisualPasteEdgeCases(t *testing.T) { sendKeys(tm, "v", "p") m := getFinalModel(t, tm) - if m.Line(0) != "XYZ" { - t.Errorf("Line(0) = %q, want 'XYZ'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "XYZ" { + t.Errorf("Line(0) = %q, want 'XYZ'", m.ActiveBuffer().Lines[0]) } }) @@ -1465,11 +1465,11 @@ func TestVisualPasteEdgeCases(t *testing.T) { sendKeys(tm, "V", "p") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "REPLACED" { - t.Errorf("Line(0) = %q, want 'REPLACED'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "REPLACED" { + t.Errorf("Line(0) = %q, want 'REPLACED'", m.ActiveBuffer().Lines[0]) } }) } diff --git a/internal/editor/integration_scroll_test.go b/internal/editor/integration_scroll_test.go index 38b8c8f..4aaaddd 100644 --- a/internal/editor/integration_scroll_test.go +++ b/internal/editor/integration_scroll_test.go @@ -26,8 +26,8 @@ func TestScrollBasic(t *testing.T) { sendKeys(tm, "G") // go to bottom m := getFinalModel(t, tm) - if m.ScrollY() != 0 { - t.Errorf("ScrollY() = %d, want 0", m.ScrollY()) + if m.ActiveWindow().ScrollY != 0 { + t.Errorf("ScrollY() = %d, want 0", m.ActiveWindow().ScrollY) } }) @@ -45,14 +45,14 @@ func TestScrollBasic(t *testing.T) { } m := getFinalModel(t, tm) - if m.CursorY() != 15 { - t.Errorf("CursorY() = %d, want 15", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 15 { + t.Errorf("CursorY() = %d, want 15", m.ActiveWindow().Cursor.Line) } // With scrollOff=8, viewport=19, cursor at 15 means: // cursor should be at position 10 from top (19-1-8=10) // so scrollY = 15 - 10 = 5 - if m.ScrollY() < 1 { - t.Errorf("ScrollY() = %d, want > 0 (should have scrolled)", m.ScrollY()) + if m.ActiveWindow().ScrollY < 1 { + t.Errorf("ScrollY() = %d, want > 0 (should have scrolled)", m.ActiveWindow().ScrollY) } }) @@ -68,13 +68,13 @@ func TestScrollBasic(t *testing.T) { } m := getFinalModel(t, tm) - if m.CursorY() != 5 { - t.Errorf("CursorY() = %d, want 5", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 5 { + t.Errorf("CursorY() = %d, want 5", m.ActiveWindow().Cursor.Line) } // Cursor at line 5 with scrollOff=8 means scrollY should be 0 // (can't scroll negative, and cursor is within safe zone from top) - if m.ScrollY() != 0 { - t.Errorf("ScrollY() = %d, want 0", m.ScrollY()) + if m.ActiveWindow().ScrollY != 0 { + t.Errorf("ScrollY() = %d, want 0", m.ActiveWindow().ScrollY) } }) @@ -84,13 +84,13 @@ func TestScrollBasic(t *testing.T) { sendKeys(tm, "G") m := getFinalModel(t, tm) - if m.CursorY() != 99 { - t.Errorf("CursorY() = %d, want 99", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 99 { + t.Errorf("CursorY() = %d, want 99", m.ActiveWindow().Cursor.Line) } // With 100 lines and viewport 18 (height - 2 for status + command bar), // max scrollY = 100 - 18 = 82 - if m.ScrollY() != 82 { - t.Errorf("ScrollY() = %d, want 82", m.ScrollY()) + if m.ActiveWindow().ScrollY != 82 { + t.Errorf("ScrollY() = %d, want 82", m.ActiveWindow().ScrollY) } }) @@ -100,11 +100,11 @@ func TestScrollBasic(t *testing.T) { sendKeys(tm, "g", "g") m := getFinalModel(t, tm) - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } - if m.ScrollY() != 0 { - t.Errorf("ScrollY() = %d, want 0", m.ScrollY()) + if m.ActiveWindow().ScrollY != 0 { + t.Errorf("ScrollY() = %d, want 0", m.ActiveWindow().ScrollY) } }) } @@ -120,8 +120,8 @@ func TestScrollEdgeCases(t *testing.T) { } m := getFinalModel(t, tm) - if m.ScrollY() < 0 { - t.Errorf("ScrollY() = %d, want >= 0", m.ScrollY()) + if m.ActiveWindow().ScrollY < 0 { + t.Errorf("ScrollY() = %d, want >= 0", m.ActiveWindow().ScrollY) } }) @@ -133,8 +133,8 @@ func TestScrollEdgeCases(t *testing.T) { m := getFinalModel(t, tm) // 30 lines, viewport 18 (height - 2) -> maxScroll = 30 - 18 = 12 maxScroll := 30 - 18 - if m.ScrollY() > maxScroll { - t.Errorf("ScrollY() = %d, want <= %d", m.ScrollY(), maxScroll) + if m.ActiveWindow().ScrollY > maxScroll { + t.Errorf("ScrollY() = %d, want <= %d", m.ActiveWindow().ScrollY, maxScroll) } }) @@ -148,9 +148,9 @@ func TestScrollEdgeCases(t *testing.T) { m := getFinalModel(t, tm) // Cursor should still be visible viewportHeight := 19 - if m.CursorY() < m.ScrollY() || m.CursorY() >= m.ScrollY()+viewportHeight { + if m.ActiveWindow().Cursor.Line < m.ActiveWindow().ScrollY || m.ActiveWindow().Cursor.Line >= m.ActiveWindow().ScrollY+viewportHeight { t.Errorf("Cursor at %d not visible in viewport [%d, %d)", - m.CursorY(), m.ScrollY(), m.ScrollY()+viewportHeight) + m.ActiveWindow().Cursor.Line, m.ActiveWindow().ScrollY, m.ActiveWindow().ScrollY+viewportHeight) } }) } @@ -166,11 +166,11 @@ func TestHalfPageScrollDown(t *testing.T) { sendKeys(tm, "ctrl+d") m := getFinalModel(t, tm) - if m.ScrollY() != 14 { - t.Errorf("ScrollY() = %d, want 14", m.ScrollY()) + if m.ActiveWindow().ScrollY != 14 { + t.Errorf("ScrollY() = %d, want 14", m.ActiveWindow().ScrollY) } - if m.CursorY() != 29 { - t.Errorf("CursorY() = %d, want 29", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 29 { + t.Errorf("CursorY() = %d, want 29", m.ActiveWindow().Cursor.Line) } }) @@ -181,7 +181,7 @@ func TestHalfPageScrollDown(t *testing.T) { sendKeys(tm, "ctrl+d") m := getFinalModel(t, tm) - relY := m.CursorY() - m.ScrollY() + relY := m.ActiveWindow().Cursor.Line - m.ActiveWindow().ScrollY if relY != 15 { t.Errorf("relative position = %d, want 15", relY) } @@ -195,11 +195,11 @@ func TestHalfPageScrollDown(t *testing.T) { sendKeys(tm, "ctrl+d") m := getFinalModel(t, tm) - if m.ScrollY() != 14 { - t.Errorf("ScrollY() = %d, want 14", m.ScrollY()) + if m.ActiveWindow().ScrollY != 14 { + t.Errorf("ScrollY() = %d, want 14", m.ActiveWindow().ScrollY) } - if m.CursorY() != 22 { - t.Errorf("CursorY() = %d, want 22", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 22 { + t.Errorf("CursorY() = %d, want 22", m.ActiveWindow().Cursor.Line) } }) @@ -213,11 +213,11 @@ func TestHalfPageScrollDown(t *testing.T) { m := getFinalModel(t, tm) maxScroll := 40 - 28 - if m.ScrollY() > maxScroll { - t.Errorf("ScrollY() = %d, want <= %d", m.ScrollY(), maxScroll) + if m.ActiveWindow().ScrollY > maxScroll { + t.Errorf("ScrollY() = %d, want <= %d", m.ActiveWindow().ScrollY, maxScroll) } - if m.CursorY() != 31 { - t.Errorf("CursorY() = %d, want 31", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 31 { + t.Errorf("CursorY() = %d, want 31", m.ActiveWindow().Cursor.Line) } }) @@ -229,11 +229,11 @@ func TestHalfPageScrollDown(t *testing.T) { sendKeys(tm, "ctrl+d") m := getFinalModel(t, tm) - if m.ScrollY() != 0 { - t.Errorf("ScrollY() = %d, want 0", m.ScrollY()) + if m.ActiveWindow().ScrollY != 0 { + t.Errorf("ScrollY() = %d, want 0", m.ActiveWindow().ScrollY) } - if m.CursorY() != 8 { - t.Errorf("CursorY() = %d, want 8", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 8 { + t.Errorf("CursorY() = %d, want 8", m.ActiveWindow().Cursor.Line) } }) @@ -253,11 +253,11 @@ func TestHalfPageScrollDown(t *testing.T) { sendKeys(tm, "ctrl+d") m := getFinalModel(t, tm) - if m.CursorY() != 22 { - t.Errorf("CursorY() = %d, want 22", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 22 { + t.Errorf("CursorY() = %d, want 22", m.ActiveWindow().Cursor.Line) } - if m.CursorX() > len(m.Line(m.CursorY())) { - t.Errorf("CursorX() = %d exceeds line length %d", m.CursorX(), len(m.Line(m.CursorY()))) + if m.ActiveWindow().Cursor.Col > len(m.ActiveBuffer().Lines[m.ActiveWindow().Cursor.Line]) { + t.Errorf("CursorX() = %d exceeds line length %d", m.ActiveWindow().Cursor.Col, len(m.ActiveBuffer().Lines[m.ActiveWindow().Cursor.Line])) } }) @@ -270,11 +270,11 @@ func TestHalfPageScrollDown(t *testing.T) { sendKeys(tm, "ctrl+d", "ctrl+d") m := getFinalModel(t, tm) - if m.ScrollY() != 28 { - t.Errorf("ScrollY() = %d, want 28", m.ScrollY()) + if m.ActiveWindow().ScrollY != 28 { + t.Errorf("ScrollY() = %d, want 28", m.ActiveWindow().ScrollY) } - if m.CursorY() != 43 { - t.Errorf("CursorY() = %d, want 43", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 43 { + t.Errorf("CursorY() = %d, want 43", m.ActiveWindow().Cursor.Line) } }) } @@ -288,11 +288,11 @@ func TestHalfPageScrollUp(t *testing.T) { sendKeys(tm, "ctrl+u") m := getFinalModel(t, tm) - if m.ScrollY() != 17 { - t.Errorf("ScrollY() = %d, want 17", m.ScrollY()) + if m.ActiveWindow().ScrollY != 17 { + t.Errorf("ScrollY() = %d, want 17", m.ActiveWindow().ScrollY) } - if m.CursorY() != 36 { - t.Errorf("CursorY() = %d, want 36", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 36 { + t.Errorf("CursorY() = %d, want 36", m.ActiveWindow().Cursor.Line) } }) @@ -303,7 +303,7 @@ func TestHalfPageScrollUp(t *testing.T) { sendKeys(tm, "ctrl+u") m := getFinalModel(t, tm) - relY := m.CursorY() - m.ScrollY() + relY := m.ActiveWindow().Cursor.Line - m.ActiveWindow().ScrollY if relY != 19 { t.Errorf("relative position = %d, want 19", relY) } @@ -317,14 +317,14 @@ func TestHalfPageScrollUp(t *testing.T) { sendKeys(tm, "ctrl+u") m := getFinalModel(t, tm) - if m.ScrollY() < 0 { - t.Errorf("ScrollY() = %d, want >= 0", m.ScrollY()) + if m.ActiveWindow().ScrollY < 0 { + t.Errorf("ScrollY() = %d, want >= 0", m.ActiveWindow().ScrollY) } - if m.ScrollY() != 0 { - t.Errorf("ScrollY() = %d, want 0", m.ScrollY()) + if m.ActiveWindow().ScrollY != 0 { + t.Errorf("ScrollY() = %d, want 0", m.ActiveWindow().ScrollY) } - if m.CursorY() != 10 { - t.Errorf("CursorY() = %d, want 10", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 10 { + t.Errorf("CursorY() = %d, want 10", m.ActiveWindow().Cursor.Line) } }) @@ -336,11 +336,11 @@ func TestHalfPageScrollUp(t *testing.T) { sendKeys(tm, "ctrl+u") m := getFinalModel(t, tm) - if m.ScrollY() != 0 { - t.Errorf("ScrollY() = %d, want 0", m.ScrollY()) + if m.ActiveWindow().ScrollY != 0 { + t.Errorf("ScrollY() = %d, want 0", m.ActiveWindow().ScrollY) } - if m.CursorY() != 8 { - t.Errorf("CursorY() = %d, want 8", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 8 { + t.Errorf("CursorY() = %d, want 8", m.ActiveWindow().Cursor.Line) } }) @@ -353,11 +353,11 @@ func TestHalfPageScrollUp(t *testing.T) { sendKeys(tm, "ctrl+u", "ctrl+u") m := getFinalModel(t, tm) - if m.ScrollY() != 33 { - t.Errorf("ScrollY() = %d, want 33", m.ScrollY()) + if m.ActiveWindow().ScrollY != 33 { + t.Errorf("ScrollY() = %d, want 33", m.ActiveWindow().ScrollY) } - if m.CursorY() != 52 { - t.Errorf("CursorY() = %d, want 52", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 52 { + t.Errorf("CursorY() = %d, want 52", m.ActiveWindow().Cursor.Line) } }) } @@ -372,11 +372,11 @@ func TestHalfPageScrollRoundTrip(t *testing.T) { sendKeys(tm, "ctrl+d", "ctrl+u") m := getFinalModel(t, tm) - if m.ScrollY() != 0 { - t.Errorf("ScrollY() = %d, want 0", m.ScrollY()) + if m.ActiveWindow().ScrollY != 0 { + t.Errorf("ScrollY() = %d, want 0", m.ActiveWindow().ScrollY) } - if m.CursorY() != 15 { - t.Errorf("CursorY() = %d, want 15", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 15 { + t.Errorf("CursorY() = %d, want 15", m.ActiveWindow().Cursor.Line) } }) @@ -389,11 +389,11 @@ func TestHalfPageScrollRoundTrip(t *testing.T) { sendKeys(tm, "ctrl+u", "ctrl+d") m := getFinalModel(t, tm) - if m.ScrollY() != 31 { - t.Errorf("ScrollY() = %d, want 31", m.ScrollY()) + if m.ActiveWindow().ScrollY != 31 { + t.Errorf("ScrollY() = %d, want 31", m.ActiveWindow().ScrollY) } - if m.CursorY() != 50 { - t.Errorf("CursorY() = %d, want 50", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 50 { + t.Errorf("CursorY() = %d, want 50", m.ActiveWindow().Cursor.Line) } }) @@ -403,11 +403,11 @@ func TestHalfPageScrollRoundTrip(t *testing.T) { sendKeys(tm, "ctrl+d", "ctrl+u", "ctrl+d", "ctrl+u") m := getFinalModel(t, tm) - if m.ScrollY() != 0 { - t.Errorf("ScrollY() = %d, want 0 after 2 round trips", m.ScrollY()) + if m.ActiveWindow().ScrollY != 0 { + t.Errorf("ScrollY() = %d, want 0 after 2 round trips", m.ActiveWindow().ScrollY) } - if m.CursorY() != 15 { - t.Errorf("CursorY() = %d, want 15 after 2 round trips", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 15 { + t.Errorf("CursorY() = %d, want 15 after 2 round trips", m.ActiveWindow().Cursor.Line) } }) } @@ -420,12 +420,12 @@ func TestScrollWithCount(t *testing.T) { sendKeys(tm, "1", "0", "j") // move down 10 lines m := getFinalModel(t, tm) - if m.CursorY() != 15 { - t.Errorf("CursorY() = %d, want 15", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 15 { + t.Errorf("CursorY() = %d, want 15", m.ActiveWindow().Cursor.Line) } // Should have scrolled since we moved past the safe zone - if m.ScrollY() == 0 { - t.Errorf("ScrollY() = %d, want > 0", m.ScrollY()) + if m.ActiveWindow().ScrollY == 0 { + t.Errorf("ScrollY() = %d, want > 0", m.ActiveWindow().ScrollY) } }) @@ -436,8 +436,8 @@ func TestScrollWithCount(t *testing.T) { sendKeys(tm, "1", "5", "k") // move up 15 lines m := getFinalModel(t, tm) - if m.CursorY() != 10 { - t.Errorf("CursorY() = %d, want 10", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 10 { + t.Errorf("CursorY() = %d, want 10", m.ActiveWindow().Cursor.Line) } }) } diff --git a/internal/editor/integration_visual_test.go b/internal/editor/integration_visual_test.go index d3a1811..44a7437 100644 --- a/internal/editor/integration_visual_test.go +++ b/internal/editor/integration_visual_test.go @@ -20,11 +20,11 @@ func TestVisualModeSelectionState(t *testing.T) { if m.Mode() != action.VisualMode { t.Errorf("Mode() = %v, want VisualMode", m.Mode()) } - if m.AnchorX() != 3 { - t.Errorf("AnchorX() = %d, want 3", m.AnchorX()) + if m.ActiveWindow().Anchor.Col != 3 { + t.Errorf("AnchorX() = %d, want 3", m.ActiveWindow().Anchor.Col) } - if m.AnchorY() != 0 { - t.Errorf("AnchorY() = %d, want 0", m.AnchorY()) + if m.ActiveWindow().Anchor.Line != 0 { + t.Errorf("AnchorY() = %d, want 0", m.ActiveWindow().Anchor.Line) } }) @@ -34,11 +34,11 @@ func TestVisualModeSelectionState(t *testing.T) { sendKeys(tm, "v", "l") m := getFinalModel(t, tm) - if m.AnchorX() != 0 { - t.Errorf("AnchorX() = %d, want 0", m.AnchorX()) + if m.ActiveWindow().Anchor.Col != 0 { + t.Errorf("AnchorX() = %d, want 0", m.ActiveWindow().Anchor.Col) } - if m.CursorX() != 1 { - t.Errorf("CursorX() = %d, want 1", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 1 { + t.Errorf("CursorX() = %d, want 1", m.ActiveWindow().Cursor.Col) } }) @@ -48,11 +48,11 @@ func TestVisualModeSelectionState(t *testing.T) { sendKeys(tm, "v", "h") m := getFinalModel(t, tm) - if m.AnchorX() != 3 { - t.Errorf("AnchorX() = %d, want 3", m.AnchorX()) + if m.ActiveWindow().Anchor.Col != 3 { + t.Errorf("AnchorX() = %d, want 3", m.ActiveWindow().Anchor.Col) } - if m.CursorX() != 2 { - t.Errorf("CursorX() = %d, want 2", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 2 { + t.Errorf("CursorX() = %d, want 2", m.ActiveWindow().Cursor.Col) } }) @@ -62,14 +62,14 @@ func TestVisualModeSelectionState(t *testing.T) { sendKeys(tm, "v", "j") m := getFinalModel(t, tm) - if m.AnchorX() != 2 { - t.Errorf("AnchorX() = %d, want 2", m.AnchorX()) + if m.ActiveWindow().Anchor.Col != 2 { + t.Errorf("AnchorX() = %d, want 2", m.ActiveWindow().Anchor.Col) } - if m.AnchorY() != 0 { - t.Errorf("AnchorY() = %d, want 0", m.AnchorY()) + if m.ActiveWindow().Anchor.Line != 0 { + t.Errorf("AnchorY() = %d, want 0", m.ActiveWindow().Anchor.Line) } - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want 1", m.ActiveWindow().Cursor.Line) } }) @@ -82,8 +82,8 @@ func TestVisualModeSelectionState(t *testing.T) { if m.Mode() != action.VisualLineMode { t.Errorf("Mode() = %v, want VisualLineMode", m.Mode()) } - if m.AnchorY() != 1 { - t.Errorf("AnchorY() = %d, want 1", m.AnchorY()) + if m.ActiveWindow().Anchor.Line != 1 { + t.Errorf("AnchorY() = %d, want 1", m.ActiveWindow().Anchor.Line) } }) @@ -96,11 +96,11 @@ func TestVisualModeSelectionState(t *testing.T) { if m.Mode() != action.VisualBlockMode { t.Errorf("Mode() = %v, want VisualBlockMode", m.Mode()) } - if m.AnchorX() != 2 { - t.Errorf("AnchorX() = %d, want 2", m.AnchorX()) + if m.ActiveWindow().Anchor.Col != 2 { + t.Errorf("AnchorX() = %d, want 2", m.ActiveWindow().Anchor.Col) } - if m.AnchorY() != 1 { - t.Errorf("AnchorY() = %d, want 1", m.AnchorY()) + if m.ActiveWindow().Anchor.Line != 1 { + t.Errorf("AnchorY() = %d, want 1", m.ActiveWindow().Anchor.Line) } }) @@ -125,11 +125,11 @@ func TestVisualModeDelete(t *testing.T) { sendKeys(tm, "v", "d") m := getFinalModel(t, tm) - if m.Line(0) != "ello" { - t.Errorf("Line(0) = %q, want \"ello\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "ello" { + t.Errorf("Line(0) = %q, want \"ello\"", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -139,11 +139,11 @@ func TestVisualModeDelete(t *testing.T) { sendKeys(tm, "v", "l", "l", "l", "d") m := getFinalModel(t, tm) - if m.Line(0) != "o world" { - t.Errorf("Line(0) = %q, want \"o world\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "o world" { + t.Errorf("Line(0) = %q, want \"o world\"", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -154,11 +154,11 @@ func TestVisualModeDelete(t *testing.T) { // anchor=3, cursor=1 → normalized start=1, end=3 → delete "ell" → "ho" m := getFinalModel(t, tm) - if m.Line(0) != "ho" { - t.Errorf("Line(0) = %q, want \"ho\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "ho" { + t.Errorf("Line(0) = %q, want \"ho\"", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 1 { - t.Errorf("CursorX() = %d, want 1", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 1 { + t.Errorf("CursorX() = %d, want 1", m.ActiveWindow().Cursor.Col) } }) @@ -169,17 +169,17 @@ func TestVisualModeDelete(t *testing.T) { // start=(2,0), end=(2,1) → prefix="he", suffix="ld" → "held" m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "held" { - t.Errorf("Line(0) = %q, want \"held\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "held" { + t.Errorf("Line(0) = %q, want \"held\"", m.ActiveBuffer().Lines[0]) } - if m.CursorX() != 2 { - t.Errorf("CursorX() = %d, want 2", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 2 { + t.Errorf("CursorX() = %d, want 2", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -189,14 +189,14 @@ func TestVisualModeDelete(t *testing.T) { sendKeys(tm, "V", "d") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "world" { - t.Errorf("Line(0) = %q, want \"world\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "world" { + t.Errorf("Line(0) = %q, want \"world\"", m.ActiveBuffer().Lines[0]) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -206,14 +206,14 @@ func TestVisualModeDelete(t *testing.T) { sendKeys(tm, "V", "j", "d") m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "testing" { - t.Errorf("Line(0) = %q, want \"testing\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "testing" { + t.Errorf("Line(0) = %q, want \"testing\"", m.ActiveBuffer().Lines[0]) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -224,11 +224,11 @@ func TestVisualModeDelete(t *testing.T) { // anchor=line2, cursor=line1 → normalized start=line1, end=line2 → delete both m := getFinalModel(t, tm) - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "hello" { - t.Errorf("Line(0) = %q, want \"hello\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello" { + t.Errorf("Line(0) = %q, want \"hello\"", m.ActiveBuffer().Lines[0]) } }) @@ -241,17 +241,17 @@ func TestVisualModeDelete(t *testing.T) { // "hello"[:0]+"hello"[2:] = "llo" // "world"[:0]+"world"[2:] = "rld" m := getFinalModel(t, tm) - if m.Line(0) != "llo" { - t.Errorf("Line(0) = %q, want \"llo\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "llo" { + t.Errorf("Line(0) = %q, want \"llo\"", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "rld" { - t.Errorf("Line(1) = %q, want \"rld\"", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "rld" { + t.Errorf("Line(1) = %q, want \"rld\"", m.ActiveBuffer().Lines[1]) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -264,11 +264,11 @@ func TestVisualModeDelete(t *testing.T) { // "hello"[:1]+"hello"[4:] = "h"+"o" = "ho" // "world"[:1]+"world"[4:] = "w"+"d" = "wd" m := getFinalModel(t, tm) - if m.Line(0) != "ho" { - t.Errorf("Line(0) = %q, want \"ho\"", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "ho" { + t.Errorf("Line(0) = %q, want \"ho\"", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "wd" { - t.Errorf("Line(1) = %q, want \"wd\"", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "wd" { + t.Errorf("Line(1) = %q, want \"wd\"", m.ActiveBuffer().Lines[1]) } }) } @@ -284,12 +284,12 @@ func TestVisualModeWordMotions(t *testing.T) { sendKeys(tm, "v", "w") m := getFinalModel(t, tm) - if m.AnchorX() != 0 { - t.Errorf("AnchorX() = %d, want 0", m.AnchorX()) + if m.ActiveWindow().Anchor.Col != 0 { + t.Errorf("AnchorX() = %d, want 0", m.ActiveWindow().Anchor.Col) } // w moves to start of "world" at col 6 - if m.CursorX() != 6 { - t.Errorf("CursorX() = %d, want 6", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 6 { + t.Errorf("CursorX() = %d, want 6", m.ActiveWindow().Cursor.Col) } }) @@ -302,8 +302,8 @@ func TestVisualModeWordMotions(t *testing.T) { m := getFinalModel(t, tm) // Deletes from 0 to 6 inclusive = "hello w", leaves "orld" - if m.Line(0) != "orld" { - t.Errorf("Line(0) = %q, want 'orld'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "orld" { + t.Errorf("Line(0) = %q, want 'orld'", m.ActiveBuffer().Lines[0]) } }) @@ -315,12 +315,12 @@ func TestVisualModeWordMotions(t *testing.T) { sendKeys(tm, "v", "e") m := getFinalModel(t, tm) - if m.AnchorX() != 0 { - t.Errorf("AnchorX() = %d, want 0", m.AnchorX()) + if m.ActiveWindow().Anchor.Col != 0 { + t.Errorf("AnchorX() = %d, want 0", m.ActiveWindow().Anchor.Col) } // e moves to end of "hello" at col 4 - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -333,8 +333,8 @@ func TestVisualModeWordMotions(t *testing.T) { m := getFinalModel(t, tm) // Deletes "hello" - if m.Line(0) != " world" { - t.Errorf("Line(0) = %q, want ' world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != " world" { + t.Errorf("Line(0) = %q, want ' world'", m.ActiveBuffer().Lines[0]) } }) @@ -346,12 +346,12 @@ func TestVisualModeWordMotions(t *testing.T) { sendKeys(tm, "v", "b") m := getFinalModel(t, tm) - if m.AnchorX() != 6 { - t.Errorf("AnchorX() = %d, want 6", m.AnchorX()) + if m.ActiveWindow().Anchor.Col != 6 { + t.Errorf("AnchorX() = %d, want 6", m.ActiveWindow().Anchor.Col) } // b moves to start of "hello" at col 0 - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -364,8 +364,8 @@ func TestVisualModeWordMotions(t *testing.T) { m := getFinalModel(t, tm) // Deletes from "h" (0) to "w" (6) inclusive - if m.Line(0) != "orld" { - t.Errorf("Line(0) = %q, want 'orld'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "orld" { + t.Errorf("Line(0) = %q, want 'orld'", m.ActiveBuffer().Lines[0]) } }) @@ -378,8 +378,8 @@ func TestVisualModeWordMotions(t *testing.T) { m := getFinalModel(t, tm) // 2w moves past "one " and "two " to start of "three" at col 8 - if m.CursorX() != 8 { - t.Errorf("CursorX() = %d, want 8", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 8 { + t.Errorf("CursorX() = %d, want 8", m.ActiveWindow().Cursor.Col) } }) } @@ -395,12 +395,12 @@ func TestVisualModeJumpMotions(t *testing.T) { sendKeys(tm, "v", "$") m := getFinalModel(t, tm) - if m.AnchorX() != 0 { - t.Errorf("AnchorX() = %d, want 0", m.AnchorX()) + if m.ActiveWindow().Anchor.Col != 0 { + t.Errorf("AnchorX() = %d, want 0", m.ActiveWindow().Anchor.Col) } // $ moves past end of line - if m.CursorX() != 11 { - t.Errorf("CursorX() = %d, want 11", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 11 { + t.Errorf("CursorX() = %d, want 11", m.ActiveWindow().Cursor.Col) } }) @@ -412,8 +412,8 @@ func TestVisualModeJumpMotions(t *testing.T) { sendKeys(tm, "v", "$", "d") m := getFinalModel(t, tm) - if m.Line(0) != "hello " { - t.Errorf("Line(0) = %q, want 'hello '", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello " { + t.Errorf("Line(0) = %q, want 'hello '", m.ActiveBuffer().Lines[0]) } }) @@ -425,11 +425,11 @@ func TestVisualModeJumpMotions(t *testing.T) { sendKeys(tm, "v", "0") m := getFinalModel(t, tm) - if m.AnchorX() != 6 { - t.Errorf("AnchorX() = %d, want 6", m.AnchorX()) + if m.ActiveWindow().Anchor.Col != 6 { + t.Errorf("AnchorX() = %d, want 6", m.ActiveWindow().Anchor.Col) } - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -442,8 +442,8 @@ func TestVisualModeJumpMotions(t *testing.T) { m := getFinalModel(t, tm) // Deletes from 'h' (0) to 'w' (6) inclusive - if m.Line(0) != "orld" { - t.Errorf("Line(0) = %q, want 'orld'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "orld" { + t.Errorf("Line(0) = %q, want 'orld'", m.ActiveBuffer().Lines[0]) } }) @@ -455,12 +455,12 @@ func TestVisualModeJumpMotions(t *testing.T) { sendKeys(tm, "v", "_") m := getFinalModel(t, tm) - if m.AnchorX() != 10 { - t.Errorf("AnchorX() = %d, want 10", m.AnchorX()) + if m.ActiveWindow().Anchor.Col != 10 { + t.Errorf("AnchorX() = %d, want 10", m.ActiveWindow().Anchor.Col) } // _ moves to first non-ws at col 4 - if m.CursorX() != 4 { - t.Errorf("CursorX() = %d, want 4", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 4 { + t.Errorf("CursorX() = %d, want 4", m.ActiveWindow().Cursor.Col) } }) @@ -472,11 +472,11 @@ func TestVisualModeJumpMotions(t *testing.T) { sendKeys(tm, "v", "G") m := getFinalModel(t, tm) - if m.AnchorY() != 0 { - t.Errorf("AnchorY() = %d, want 0", m.AnchorY()) + if m.ActiveWindow().Anchor.Line != 0 { + t.Errorf("AnchorY() = %d, want 0", m.ActiveWindow().Anchor.Line) } - if m.CursorY() != 2 { - t.Errorf("CursorY() = %d, want 2", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 2 { + t.Errorf("CursorY() = %d, want 2", m.ActiveWindow().Cursor.Line) } }) @@ -490,11 +490,11 @@ func TestVisualModeJumpMotions(t *testing.T) { m := getFinalModel(t, tm) // G goes to last line at same col, deletes from (0,3) to (2,3) // Keeps "lin" from first line + "e 3" from last line = "lin 3" - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "lin 3" { - t.Errorf("Line(0) = %q, want 'lin 3'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "lin 3" { + t.Errorf("Line(0) = %q, want 'lin 3'", m.ActiveBuffer().Lines[0]) } }) @@ -506,11 +506,11 @@ func TestVisualModeJumpMotions(t *testing.T) { sendKeys(tm, "v", "g", "g") m := getFinalModel(t, tm) - if m.AnchorY() != 2 { - t.Errorf("AnchorY() = %d, want 2", m.AnchorY()) + if m.ActiveWindow().Anchor.Line != 2 { + t.Errorf("AnchorY() = %d, want 2", m.ActiveWindow().Anchor.Line) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -524,11 +524,11 @@ func TestVisualModeJumpMotions(t *testing.T) { m := getFinalModel(t, tm) // gg goes to first line at same col, deletes selection // Keeps "lin" from first line + " 3" from last line = "lin 3" - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "lin 3" { - t.Errorf("Line(0) = %q, want 'lin 3'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "lin 3" { + t.Errorf("Line(0) = %q, want 'lin 3'", m.ActiveBuffer().Lines[0]) } }) } @@ -544,11 +544,11 @@ func TestVisualLineModeJumpMotions(t *testing.T) { sendKeys(tm, "V", "G") m := getFinalModel(t, tm) - if m.AnchorY() != 0 { - t.Errorf("AnchorY() = %d, want 0", m.AnchorY()) + if m.ActiveWindow().Anchor.Line != 0 { + t.Errorf("AnchorY() = %d, want 0", m.ActiveWindow().Anchor.Line) } - if m.CursorY() != 2 { - t.Errorf("CursorY() = %d, want 2", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 2 { + t.Errorf("CursorY() = %d, want 2", m.ActiveWindow().Cursor.Line) } }) @@ -561,11 +561,11 @@ func TestVisualLineModeJumpMotions(t *testing.T) { m := getFinalModel(t, tm) // All lines deleted, should have empty buffer - if m.LineCount() != 1 { - t.Errorf("LineCount() = %d, want 1", m.LineCount()) + if m.ActiveBuffer().LineCount() != 1 { + t.Errorf("LineCount() = %d, want 1", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "" { - t.Errorf("Line(0) = %q, want ''", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "" { + t.Errorf("Line(0) = %q, want ''", m.ActiveBuffer().Lines[0]) } }) @@ -577,11 +577,11 @@ func TestVisualLineModeJumpMotions(t *testing.T) { sendKeys(tm, "V", "g", "g") m := getFinalModel(t, tm) - if m.AnchorY() != 2 { - t.Errorf("AnchorY() = %d, want 2", m.AnchorY()) + if m.ActiveWindow().Anchor.Line != 2 { + t.Errorf("AnchorY() = %d, want 2", m.ActiveWindow().Anchor.Line) } - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) } diff --git a/internal/editor/integration_yank_test.go b/internal/editor/integration_yank_test.go index 3dfa499..415157f 100644 --- a/internal/editor/integration_yank_test.go +++ b/internal/editor/integration_yank_test.go @@ -43,17 +43,17 @@ func TestYankLineBasic(t *testing.T) { sendKeys(tm, "y", "y") m := getFinalModel(t, tm) - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 1" { - t.Errorf("Line(0) = %q, want 'line 1'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 1" { + t.Errorf("Line(0) = %q, want 'line 1'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "line 2" { - t.Errorf("Line(1) = %q, want 'line 2'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line 2" { + t.Errorf("Line(1) = %q, want 'line 2'", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "line 3" { - t.Errorf("Line(2) = %q, want 'line 3'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "line 3" { + t.Errorf("Line(2) = %q, want 'line 3'", m.ActiveBuffer().Lines[2]) } }) @@ -65,11 +65,11 @@ func TestYankLineBasic(t *testing.T) { sendKeys(tm, "y", "y") m := getFinalModel(t, tm) - if m.CursorY() != 1 { - t.Errorf("CursorY() = %d, want 1", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 1 { + t.Errorf("CursorY() = %d, want 1", m.ActiveWindow().Cursor.Line) } - if m.CursorX() != 3 { - t.Errorf("CursorX() = %d, want 3", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 3 { + t.Errorf("CursorX() = %d, want 3", m.ActiveWindow().Cursor.Col) } }) @@ -174,8 +174,8 @@ func TestYankLineWithCount(t *testing.T) { sendKeys(tm, "3", "y", "y") m := getFinalModel(t, tm) - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } }) } @@ -376,8 +376,8 @@ func TestYankWithLinewiseMotions(t *testing.T) { sendKeys(tm, "y", "j") m := getFinalModel(t, tm) - if m.CursorY() != 0 { - t.Errorf("CursorY() = %d, want 0", m.CursorY()) + if m.ActiveWindow().Cursor.Line != 0 { + t.Errorf("CursorY() = %d, want 0", m.ActiveWindow().Cursor.Line) } }) @@ -389,8 +389,8 @@ func TestYankWithLinewiseMotions(t *testing.T) { sendKeys(tm, "y", "G") m := getFinalModel(t, tm) - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } }) } @@ -570,8 +570,8 @@ func TestYankWithCharwiseMotions(t *testing.T) { sendKeys(tm, "y", "w") m := getFinalModel(t, tm) - if m.CursorX() != 0 { - t.Errorf("CursorX() = %d, want 0", m.CursorX()) + if m.ActiveWindow().Cursor.Col != 0 { + t.Errorf("CursorX() = %d, want 0", m.ActiveWindow().Cursor.Col) } }) @@ -583,8 +583,8 @@ func TestYankWithCharwiseMotions(t *testing.T) { sendKeys(tm, "y", "w") m := getFinalModel(t, tm) - if m.Line(0) != "hello world" { - t.Errorf("Line(0) = %q, want 'hello world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello world" { + t.Errorf("Line(0) = %q, want 'hello world'", m.ActiveBuffer().Lines[0]) } }) } @@ -659,8 +659,8 @@ func TestYankVisualCharwise(t *testing.T) { sendKeys(tm, "v", "l", "l", "l", "l", "y") m := getFinalModel(t, tm) - if m.Line(0) != "hello world" { - t.Errorf("Line(0) = %q, want 'hello world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello world" { + t.Errorf("Line(0) = %q, want 'hello world'", m.ActiveBuffer().Lines[0]) } }) } @@ -901,11 +901,11 @@ func TestYankRegisterBehavior(t *testing.T) { sendKeys(tm, "p") // paste m := getFinalModel(t, tm) - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(1) != "to copy" { - t.Errorf("Line(1) = %q, want 'to copy'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "to copy" { + t.Errorf("Line(1) = %q, want 'to copy'", m.ActiveBuffer().Lines[1]) } }) } @@ -1053,8 +1053,8 @@ func TestVisualYankPasteRoundTrip(t *testing.T) { sendKeys(tm, "v", "l", "l", "l", "l", "y", "$", "p") m := getFinalModel(t, tm) - if m.Line(0) != "hello worldhello" { - t.Errorf("Line(0) = %q, want 'hello worldhello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello worldhello" { + t.Errorf("Line(0) = %q, want 'hello worldhello'", m.ActiveBuffer().Lines[0]) } }) @@ -1067,8 +1067,8 @@ func TestVisualYankPasteRoundTrip(t *testing.T) { sendKeys(tm, "v", "$", "y", "0", "P") m := getFinalModel(t, tm) - if m.Line(0) != "worldhello world" { - t.Errorf("Line(0) = %q, want 'worldhello world'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "worldhello world" { + t.Errorf("Line(0) = %q, want 'worldhello world'", m.ActiveBuffer().Lines[0]) } }) @@ -1081,11 +1081,11 @@ func TestVisualYankPasteRoundTrip(t *testing.T) { sendKeys(tm, "V", "y", "j", "p") m := getFinalModel(t, tm) - if m.LineCount() != 4 { - t.Errorf("LineCount() = %d, want 4", m.LineCount()) + if m.ActiveBuffer().LineCount() != 4 { + t.Errorf("LineCount() = %d, want 4", m.ActiveBuffer().LineCount()) } - if m.Line(2) != "line 1" { - t.Errorf("Line(2) = %q, want 'line 1'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "line 1" { + t.Errorf("Line(2) = %q, want 'line 1'", m.ActiveBuffer().Lines[2]) } }) @@ -1098,14 +1098,14 @@ func TestVisualYankPasteRoundTrip(t *testing.T) { sendKeys(tm, "V", "j", "y", "G", "p") m := getFinalModel(t, tm) - if m.LineCount() != 6 { - t.Errorf("LineCount() = %d, want 6", m.LineCount()) + if m.ActiveBuffer().LineCount() != 6 { + t.Errorf("LineCount() = %d, want 6", m.ActiveBuffer().LineCount()) } - if m.Line(4) != "line 1" { - t.Errorf("Line(4) = %q, want 'line 1'", m.Line(4)) + if m.ActiveBuffer().Lines[4] != "line 1" { + t.Errorf("Line(4) = %q, want 'line 1'", m.ActiveBuffer().Lines[4]) } - if m.Line(5) != "line 2" { - t.Errorf("Line(5) = %q, want 'line 2'", m.Line(5)) + if m.ActiveBuffer().Lines[5] != "line 2" { + t.Errorf("Line(5) = %q, want 'line 2'", m.ActiveBuffer().Lines[5]) } }) @@ -1118,14 +1118,14 @@ func TestVisualYankPasteRoundTrip(t *testing.T) { sendKeys(tm, "V", "y", "g", "g", "P") m := getFinalModel(t, tm) - if m.LineCount() != 4 { - t.Errorf("LineCount() = %d, want 4", m.LineCount()) + if m.ActiveBuffer().LineCount() != 4 { + t.Errorf("LineCount() = %d, want 4", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 3" { - t.Errorf("Line(0) = %q, want 'line 3'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 3" { + t.Errorf("Line(0) = %q, want 'line 3'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "line 1" { - t.Errorf("Line(1) = %q, want 'line 1'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line 1" { + t.Errorf("Line(1) = %q, want 'line 1'", m.ActiveBuffer().Lines[1]) } }) @@ -1137,17 +1137,17 @@ func TestVisualYankPasteRoundTrip(t *testing.T) { sendKeys(tm, "y", "y", "p") m := getFinalModel(t, tm) - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "original" { - t.Errorf("Line(0) = %q, want 'original'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "original" { + t.Errorf("Line(0) = %q, want 'original'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "original" { - t.Errorf("Line(1) = %q, want 'original'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "original" { + t.Errorf("Line(1) = %q, want 'original'", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "other" { - t.Errorf("Line(2) = %q, want 'other'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "other" { + t.Errorf("Line(2) = %q, want 'other'", m.ActiveBuffer().Lines[2]) } }) @@ -1159,17 +1159,17 @@ func TestVisualYankPasteRoundTrip(t *testing.T) { sendKeys(tm, "y", "y", "P") m := getFinalModel(t, tm) - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "original" { - t.Errorf("Line(0) = %q, want 'original'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "original" { + t.Errorf("Line(0) = %q, want 'original'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "other" { - t.Errorf("Line(1) = %q, want 'other'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "other" { + t.Errorf("Line(1) = %q, want 'other'", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "other" { - t.Errorf("Line(2) = %q, want 'other'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "other" { + t.Errorf("Line(2) = %q, want 'other'", m.ActiveBuffer().Lines[2]) } }) @@ -1182,8 +1182,8 @@ func TestVisualYankPasteRoundTrip(t *testing.T) { sendKeys(tm, "y", "w", "$", "p") m := getFinalModel(t, tm) - if m.Line(0) != "hello worldhello " { - t.Errorf("Line(0) = %q, want 'hello worldhello '", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello worldhello " { + t.Errorf("Line(0) = %q, want 'hello worldhello '", m.ActiveBuffer().Lines[0]) } }) @@ -1196,8 +1196,8 @@ func TestVisualYankPasteRoundTrip(t *testing.T) { sendKeys(tm, "y", "e", "$", "p") m := getFinalModel(t, tm) - if m.Line(0) != "hello worldhello" { - t.Errorf("Line(0) = %q, want 'hello worldhello'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "hello worldhello" { + t.Errorf("Line(0) = %q, want 'hello worldhello'", m.ActiveBuffer().Lines[0]) } }) @@ -1210,8 +1210,8 @@ func TestVisualYankPasteRoundTrip(t *testing.T) { sendKeys(tm, "v", "l", "l", "y", "$", "p") m := getFinalModel(t, tm) - if m.Line(0) != "abcdefghcde" { - t.Errorf("Line(0) = %q, want 'abcdefghcde'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "abcdefghcde" { + t.Errorf("Line(0) = %q, want 'abcdefghcde'", m.ActiveBuffer().Lines[0]) } }) @@ -1243,17 +1243,17 @@ func TestVisualYankPasteRoundTrip(t *testing.T) { sendKeys(tm, "d", "d", "p") m := getFinalModel(t, tm) - if m.LineCount() != 3 { - t.Errorf("LineCount() = %d, want 3", m.LineCount()) + if m.ActiveBuffer().LineCount() != 3 { + t.Errorf("LineCount() = %d, want 3", m.ActiveBuffer().LineCount()) } - if m.Line(0) != "line 2" { - t.Errorf("Line(0) = %q, want 'line 2'", m.Line(0)) + if m.ActiveBuffer().Lines[0] != "line 2" { + t.Errorf("Line(0) = %q, want 'line 2'", m.ActiveBuffer().Lines[0]) } - if m.Line(1) != "line 1" { - t.Errorf("Line(1) = %q, want 'line 1'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line 1" { + t.Errorf("Line(1) = %q, want 'line 1'", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "line 3" { - t.Errorf("Line(2) = %q, want 'line 3'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "line 3" { + t.Errorf("Line(2) = %q, want 'line 3'", m.ActiveBuffer().Lines[2]) } }) @@ -1266,21 +1266,21 @@ func TestVisualYankPasteRoundTrip(t *testing.T) { sendKeys(tm, "2", "y", "y", "2", "p") m := getFinalModel(t, tm) - if m.LineCount() != 7 { - t.Errorf("LineCount() = %d, want 7", m.LineCount()) + if m.ActiveBuffer().LineCount() != 7 { + t.Errorf("LineCount() = %d, want 7", m.ActiveBuffer().LineCount()) } // Original + 2 copies of 2 lines = 3 + 4 = 7 - if m.Line(1) != "line 1" { - t.Errorf("Line(1) = %q, want 'line 1'", m.Line(1)) + if m.ActiveBuffer().Lines[1] != "line 1" { + t.Errorf("Line(1) = %q, want 'line 1'", m.ActiveBuffer().Lines[1]) } - if m.Line(2) != "line 2" { - t.Errorf("Line(2) = %q, want 'line 2'", m.Line(2)) + if m.ActiveBuffer().Lines[2] != "line 2" { + t.Errorf("Line(2) = %q, want 'line 2'", m.ActiveBuffer().Lines[2]) } - if m.Line(3) != "line 1" { - t.Errorf("Line(3) = %q, want 'line 1'", m.Line(3)) + if m.ActiveBuffer().Lines[3] != "line 1" { + t.Errorf("Line(3) = %q, want 'line 1'", m.ActiveBuffer().Lines[3]) } - if m.Line(4) != "line 2" { - t.Errorf("Line(4) = %q, want 'line 2'", m.Line(4)) + if m.ActiveBuffer().Lines[4] != "line 2" { + t.Errorf("Line(4) = %q, want 'line 2'", m.ActiveBuffer().Lines[4]) } }) } diff --git a/internal/editor/model.go b/internal/editor/model.go index 727aeb8..9855455 100644 --- a/internal/editor/model.go +++ b/internal/editor/model.go @@ -44,6 +44,9 @@ type Model struct { // Registers registers map[rune]action.Register // name -> register + + // Visual styles + styles Styles } // Model.Init: Initialize the model and start any commands that may need to run. Required @@ -285,6 +288,16 @@ func (m *Model) SetSettings(s action.Settings) { m.settings = s } +// Model.Styles: Returns the visual styles used for rendering. +func (m *Model) Styles() Styles { + return m.styles +} + +// Model.SetStyles: Sets the visual styles used for rendering. +func (m *Model) SetStyles(s Styles) { + m.styles = s +} + // ================================================== // Registers // ================================================== diff --git a/internal/editor/model_builder.go b/internal/editor/model_builder.go index 98fd332..9798955 100644 --- a/internal/editor/model_builder.go +++ b/internal/editor/model_builder.go @@ -28,6 +28,7 @@ func NewModelBuilder() *ModelBuilder { commandOutput: "", settings: action.NewDefaultSettings(), registers: action.DefaultRegisters(), + styles: DefaultStyles(), }, } } @@ -126,6 +127,12 @@ func (mb *ModelBuilder) WithCommandOutput(output string) *ModelBuilder { return mb } +// ModelBuilder.WithStyles: Set the visual styling for the editor. +func (mb *ModelBuilder) WithStyles(styles Styles) *ModelBuilder { + mb.model.styles = styles + return mb +} + // ModelBuilder.Build: Build and return the configured Model instance. func (mb *ModelBuilder) Build() *Model { return &mb.model diff --git a/internal/editor/style.go b/internal/editor/style.go index 4cf497a..b2d2516 100644 --- a/internal/editor/style.go +++ b/internal/editor/style.go @@ -5,48 +5,121 @@ import ( "github.com/charmbracelet/lipgloss" ) -func (m Model) cursorStyle() lipgloss.Style { - switch m.mode { - case action.NormalMode, - action.VisualMode, - action.VisualBlockMode, - action.VisualLineMode: - // Block cursor for normal mode - return lipgloss.NewStyle().Reverse(true) +// Styles holds all the visual styling for the editor. +// Passed to Window.View() so windows can render themselves. +type Styles struct { + // Cursor styles by mode + CursorNormal lipgloss.Style + CursorInsert lipgloss.Style + CursorCommand lipgloss.Style + + // Gutter (line numbers) + Gutter lipgloss.Style + GutterCurrentLine lipgloss.Style + + // Visual mode + VisualHighlight lipgloss.Style + VisualAnchor lipgloss.Style // debugging + + // Status bar + StatusBar lipgloss.Style + StatusBarActive lipgloss.Style + + // Command line + CommandError lipgloss.Style +} + +// DefaultStyles returns the default editor color scheme. +func DefaultStyles() Styles { + return Styles{ + CursorNormal: lipgloss.NewStyle().Reverse(true), + CursorInsert: lipgloss.NewStyle().Underline(true), + CursorCommand: lipgloss.NewStyle().Reverse(true), + + Gutter: lipgloss.NewStyle(). + Background(lipgloss.Color("236")). + Foreground(lipgloss.Color("243")), + + GutterCurrentLine: lipgloss.NewStyle(). + Background(lipgloss.Color("236")). + Foreground(lipgloss.Color("#d69d00")), + + VisualHighlight: lipgloss.NewStyle(). + Background(lipgloss.Color("#7a6a00")), + + VisualAnchor: lipgloss.NewStyle(). + Background(lipgloss.Color("#a89020")), + + StatusBar: lipgloss.NewStyle(). + Background(lipgloss.Color("236")). + Foreground(lipgloss.Color("243")), + + StatusBarActive: lipgloss.NewStyle(). + Background(lipgloss.Color("62")). + Foreground(lipgloss.Color("230")), + + CommandError: lipgloss.NewStyle(). + Foreground(lipgloss.Color("#e3203a")), + } +} + +// CursorStyle returns the appropriate cursor style for the given mode. +func (s Styles) CursorStyle(mode action.Mode) lipgloss.Style { + switch mode { case action.InsertMode: - // Bar/underline for insert mode - return lipgloss.NewStyle().Underline(true) + return s.CursorInsert case action.CommandMode: - return lipgloss.NewStyle().Reverse(true) + return s.CursorCommand default: - return lipgloss.NewStyle().Reverse(true) + return s.CursorNormal } } -// DEBUGGING STYLE -func (m Model) visualAnchorStyle() lipgloss.Style { - bg := lipgloss.Color("#a89020") - return lipgloss.NewStyle().Background(bg) -} - -func (m Model) gutterStyle(currentLine bool) lipgloss.Style { - bg := lipgloss.Color("236") - fg := lipgloss.Color("243") - if currentLine { - fg = lipgloss.Color("#d69d00") - } - return lipgloss.NewStyle(). - Width(m.Settings().GutterSize). - Background(bg). - Foreground(fg) -} - -func (m Model) visualHighlightStyle() lipgloss.Style { - bg := lipgloss.Color("#7a6a00") - return lipgloss.NewStyle().Background(bg) -} - -func (m Model) commandErrorStyle() lipgloss.Style { - fg := lipgloss.Color("#e3203a") - return lipgloss.NewStyle().Foreground(fg) -} +// ================================================== +// Deprecated +// ================================================== +// func (m Model) cursorStyle() lipgloss.Style { +// switch m.mode { +// case action.NormalMode, +// action.VisualMode, +// action.VisualBlockMode, +// action.VisualLineMode: +// // Block cursor for normal mode +// return lipgloss.NewStyle().Reverse(true) +// case action.InsertMode: +// // Bar/underline for insert mode +// return lipgloss.NewStyle().Underline(true) +// case action.CommandMode: +// return lipgloss.NewStyle().Reverse(true) +// default: +// return lipgloss.NewStyle().Reverse(true) +// } +// } +// +// // DEBUGGING STYLE +// func (m Model) visualAnchorStyle() lipgloss.Style { +// bg := lipgloss.Color("#a89020") +// return lipgloss.NewStyle().Background(bg) +// } +// +// func (m Model) gutterStyle(currentLine bool) lipgloss.Style { +// bg := lipgloss.Color("236") +// fg := lipgloss.Color("243") +// if currentLine { +// fg = lipgloss.Color("#d69d00") +// } +// return lipgloss.NewStyle(). +// Width(m.Settings().GutterSize). +// Background(bg). +// Foreground(fg) +// } +// +// func (m Model) visualHighlightStyle() lipgloss.Style { +// bg := lipgloss.Color("#7a6a00") +// return lipgloss.NewStyle().Background(bg) +// } +// +// func (m Model) commandErrorStyle() lipgloss.Style { +// fg := lipgloss.Color("#e3203a") +// return lipgloss.NewStyle().Foreground(fg) +// } diff --git a/internal/editor/update.go b/internal/editor/update.go index 352f270..fdf5cfe 100644 --- a/internal/editor/update.go +++ b/internal/editor/update.go @@ -56,7 +56,8 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } // Keep cursor in view after any update - m.AdjustScroll() + win := m.ActiveWindow() + win.AdjustScroll() return m, cmd } diff --git a/internal/editor/view.go b/internal/editor/view.go index 7c61c63..ea58a0f 100644 --- a/internal/editor/view.go +++ b/internal/editor/view.go @@ -8,18 +8,20 @@ import ( ) func posInsideSelection(m Model, col, line int) bool { + win := m.ActiveWindow() + switch m.Mode() { case action.VisualLineMode: - startY := min(m.AnchorY(), m.CursorY()) - endY := max(m.AnchorY(), m.CursorY()) + startY := min(win.Anchor.Line, win.Cursor.Line) + endY := max(win.Anchor.Line, win.Cursor.Line) return line >= startY && line <= endY case action.VisualMode: - ax := m.AnchorX() - ay := m.AnchorY() + ax := win.Anchor.Col + ay := win.Anchor.Line - cx := m.CursorX() - cy := m.CursorY() + cx := win.Cursor.Col + cy := win.Cursor.Line // Normalize so start is always before end in document order var startX, startY, endX, endY int @@ -37,10 +39,10 @@ func posInsideSelection(m Model, col, line int) bool { return afterStart && beforeEnd case action.VisualBlockMode: - startX := min(m.AnchorX(), m.CursorX()) - startY := min(m.AnchorY(), m.CursorY()) - endX := max(m.AnchorX(), m.CursorX()) - endY := max(m.AnchorY(), m.CursorY()) + startX := min(win.Anchor.Col, win.Cursor.Col) + startY := min(win.Anchor.Line, win.Cursor.Line) + endX := max(win.Anchor.Col, win.Cursor.Col) + endY := max(win.Anchor.Line, win.Cursor.Line) return col >= startX && col <= endX && line >= startY && line <= endY @@ -51,21 +53,25 @@ func posInsideSelection(m Model, col, line int) bool { } func posIsAnchor(m Model, col, line int) bool { - ax := m.AnchorX() - ay := m.AnchorY() + win := m.ActiveWindow() + ax := win.Anchor.Col + ay := win.Anchor.Line return col == ax && line == ay } func (m Model) View() string { + win := m.ActiveWindow() + buf := m.ActiveBuffer() + var view strings.Builder - viewportHeight := m.ViewPortH() - start := m.ScrollY() - end := m.ScrollY() + viewportHeight + viewportHeight := win.Height - 2 + start := win.ScrollY + end := win.ScrollY + viewportHeight for i := start; i < end; i++ { - if i < m.LineCount() { + if i < buf.LineCount() { if m.Settings().Number || m.Settings().RelativeNumber { var ( @@ -76,11 +82,11 @@ func (m Model) View() string { if m.Settings().RelativeNumber { // Relative line numbers: show distance from cursor, current line shows absolute - if i > m.CursorY() { - lineNumber = i - m.CursorY() + if i > win.Cursor.Line { + lineNumber = i - win.Cursor.Line gutter = fmt.Sprintf("%*d ", m.Settings().GutterSize-1, lineNumber) - } else if i < m.CursorY() { - lineNumber = m.CursorY() - i + } else if i < win.Cursor.Line { + lineNumber = win.Cursor.Line - i gutter = fmt.Sprintf("%*d ", m.Settings().GutterSize-1, lineNumber) } else { // Current line: show absolute number if Number is also set, otherwise show 0 @@ -95,31 +101,35 @@ func (m Model) View() string { } else if m.Settings().Number { // Absolute line numbers only lineNumber = i + 1 - currentLine = (i == m.CursorY()) + currentLine = (i == win.Cursor.Line) gutter = fmt.Sprintf("%*d ", m.Settings().GutterSize-1, lineNumber) } - view.WriteString(m.gutterStyle(currentLine).Render(gutter)) + if currentLine { + view.WriteString(m.Styles().GutterCurrentLine.Render(gutter)) + } else { + view.WriteString(m.Styles().Gutter.Render(gutter)) + } } - runes := []rune(m.Line(i)) + runes := []rune(buf.Lines[i]) for x := 0; x <= len(runes); x++ { - if m.CursorY() == i && m.CursorX() == x { + if win.Cursor.Line == i && win.Cursor.Col == x { if x < len(runes) { - view.WriteString(m.cursorStyle().Render(string(runes[x]))) + view.WriteString(m.Styles().CursorStyle(m.Mode()).Render(string(runes[x]))) } else { - view.WriteString(m.cursorStyle().Render(" ")) + view.WriteString(m.Styles().CursorStyle(m.Mode()).Render(" ")) } } else if x < len(runes) { if m.Mode().IsVisualMode() && posIsAnchor(m, x, i) { - view.WriteString(m.visualAnchorStyle().Render(string(runes[x]))) + view.WriteString(m.Styles().VisualAnchor.Render(string(runes[x]))) } else if m.Mode().IsVisualMode() && posInsideSelection(m, x, i) { - view.WriteString(m.visualHighlightStyle().Render(string(runes[x]))) + view.WriteString(m.Styles().VisualHighlight.Render(string(runes[x]))) } else { view.WriteRune(runes[x]) } // To highlight blank lines when in visual mode } else if m.Mode().IsVisualMode() && posInsideSelection(m, x, i) { - view.WriteString(m.visualHighlightStyle().Render(" ")) + view.WriteString(m.Styles().VisualHighlight.Render(" ")) } } } else { @@ -162,11 +172,13 @@ func leftBar(m Model) string { } func rightBar(m Model) (bar string) { + win := m.ActiveWindow() + if m.Mode().IsVisualMode() { - lineCount := max(m.AnchorY(), m.CursorY()) - min(m.AnchorY(), m.CursorY()) + 1 - bar = fmt.Sprintf("%d:%d <%d>", m.CursorY(), m.CursorX(), lineCount) + lineCount := max(win.Anchor.Line, win.Cursor.Line) - min(win.Anchor.Line, win.Cursor.Line) + 1 + bar = fmt.Sprintf("%d:%d <%d>", win.Cursor.Line, win.Cursor.Col, lineCount) } else { - bar = fmt.Sprintf("%d:%d ", m.CursorY(), m.CursorX()) + bar = fmt.Sprintf("%d:%d ", win.Cursor.Line, win.Cursor.Col) } return } @@ -178,18 +190,18 @@ func drawCommandBar(m Model) (bar string) { cur := m.CommandCursor() for i := 0; i < len(cmd); i++ { if i == cur { - bar += m.cursorStyle().Render(string(cmd[i])) + bar += m.Styles().CursorStyle(m.Mode()).Render(string(cmd[i])) } else { bar += string(cmd[i]) } } // Cursor at end of command if cur >= len(cmd) { - bar += m.cursorStyle().Render(" ") + bar += m.Styles().CursorStyle(m.Mode()).Render(" ") } // bar = fmt.Sprintf("%s %d", bar, cur) } else if m.CommandError() != nil { - bar = m.commandErrorStyle().Render(m.CommandError().Error()) + bar = m.Styles().CommandError.Render(m.CommandError().Error()) } else if strings.TrimSpace(m.CommandOutput()) != "" { bar = m.CommandOutput() } else if strings.TrimSpace(m.Command()) != "" { diff --git a/internal/input/handler.go b/internal/input/handler.go index f94323b..42ed163 100644 --- a/internal/input/handler.go +++ b/internal/input/handler.go @@ -14,11 +14,6 @@ const ( StateMotionCount ) -// PositionGetter is used to get cursor position for operator ranges -type PositionGetter interface { - GetCursorPosition() *action.Position -} - type Handler struct { state InputState count1 int @@ -181,6 +176,7 @@ func (h *Handler) handleInitial(m action.Model, kind string, binding any, key st func (h *Handler) handleAfterOperator(m action.Model, kind string, binding any, key string) tea.Cmd { count := h.effectiveCount() + win := m.ActiveWindow() // dd, yy, cc - same operator key pressed twice if kind == "operator" && key == h.operatorKey { @@ -201,11 +197,10 @@ func (h *Handler) handleAfterOperator(m action.Model, kind string, binding any, mot = r.WithCount(count).(action.Motion) } // Get range and motion type - pg := m.(PositionGetter) - start := pg.GetCursorPosition() + start := win.Cursor mot.Execute(m) - end := pg.GetCursorPosition() - cmd := h.operator.Operate(m, *start, *end, mot.Type()) + end := win.Cursor + cmd := h.operator.Operate(m, start, end, mot.Type()) h.Reset() return cmd } @@ -302,8 +297,9 @@ func (h *Handler) handleCommandKey(m action.Model, key string) tea.Cmd { } func normalizeVisualSelection(m action.Model) (action.Position, action.Position) { - a := action.Position{Line: m.AnchorY(), Col: m.AnchorX()} - c := action.Position{Line: m.CursorY(), Col: m.CursorX()} + win := m.ActiveWindow() + a := action.Position{Line: win.Anchor.Line, Col: win.Anchor.Col} + c := action.Position{Line: win.Cursor.Line, Col: win.Cursor.Col} if a.Line < c.Line || (a.Line == c.Line && a.Col <= c.Col) { return a, c } diff --git a/internal/motion/basic.go b/internal/motion/basic.go index ee22e4c..faffcd3 100644 --- a/internal/motion/basic.go +++ b/internal/motion/basic.go @@ -1,8 +1,8 @@ package motion import ( - tea "github.com/charmbracelet/bubbletea" "git.gophernest.net/azpect/TextEditor/internal/action" + tea "github.com/charmbracelet/bubbletea" ) // MoveDown implements Motion (j) - linewise @@ -11,10 +11,11 @@ type MoveDown struct { } func (a MoveDown) Execute(m action.Model) tea.Cmd { - for i := 0; i < a.Count && m.CursorY() < m.LineCount()-1; i++ { - m.SetCursorY(m.CursorY() + 1) + 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) } - m.ClampCursorX() return nil } @@ -30,10 +31,10 @@ type MoveUp struct { } func (a MoveUp) Execute(m action.Model) tea.Cmd { - for i := 0; i < a.Count && m.CursorY() > 0; i++ { - m.SetCursorY(m.CursorY() - 1) + win := m.ActiveWindow() + for i := 0; i < a.Count && win.Cursor.Line > 0; i++ { + win.SetCursorLine(win.Cursor.Line - 1) } - m.ClampCursorX() return nil } @@ -49,10 +50,10 @@ type MoveLeft struct { } func (a MoveLeft) Execute(m action.Model) tea.Cmd { - for i := 0; i < a.Count && m.CursorX() > 0; i++ { - m.SetCursorX(m.CursorX() - 1) + win := m.ActiveWindow() + for i := 0; i < a.Count && win.Cursor.Col > 0; i++ { + win.SetCursorCol(win.Cursor.Col - 1) } - m.ClampCursorX() return nil } @@ -68,11 +69,12 @@ type MoveRight struct { } func (a MoveRight) Execute(m action.Model) tea.Cmd { - lineLen := len(m.Line(m.CursorY())) - for i := 0; i < a.Count && m.CursorX() <= lineLen; i++ { - m.SetCursorX(m.CursorX() + 1) + 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) } - m.ClampCursorX() return nil } diff --git a/internal/motion/jump.go b/internal/motion/jump.go index ab85204..87997c2 100644 --- a/internal/motion/jump.go +++ b/internal/motion/jump.go @@ -9,8 +9,8 @@ import ( type MoveToTop struct{} func (a MoveToTop) Execute(m action.Model) tea.Cmd { - m.SetCursorY(0) - m.ClampCursorX() + win := m.ActiveWindow() + win.SetCursorLine(0) return nil } @@ -20,8 +20,9 @@ func (a MoveToTop) Type() action.MotionType { return action.Linewise } type MoveToBottom struct{} func (a MoveToBottom) Execute(m action.Model) tea.Cmd { - m.SetCursorY(m.LineCount() - 1) - m.ClampCursorX() + win := m.ActiveWindow() + buf := m.ActiveBuffer() + win.SetCursorLine(buf.LineCount() - 1) return nil } @@ -31,8 +32,8 @@ func (a MoveToBottom) Type() action.MotionType { return action.Linewise } type MoveToLineStart struct{} func (a MoveToLineStart) Execute(m action.Model) tea.Cmd { - m.SetCursorX(0) - m.ClampCursorX() + win := m.ActiveWindow() + win.SetCursorCol(0) return nil } @@ -42,8 +43,9 @@ func (a MoveToLineStart) Type() action.MotionType { return action.CharwiseExclus type MoveToLineEnd struct{} func (a MoveToLineEnd) Execute(m action.Model) tea.Cmd { - m.SetCursorX(len(m.Line(m.CursorY()))) - m.ClampCursorX() + win := m.ActiveWindow() + buf := m.ActiveBuffer() + win.SetCursorCol(len(buf.Lines[win.Cursor.Line])) return nil } @@ -53,7 +55,10 @@ func (a MoveToLineEnd) Type() action.MotionType { return action.CharwiseInclusiv type MoveToLineContentStart struct{} func (a MoveToLineContentStart) Execute(m action.Model) tea.Cmd { - line := m.Line(m.CursorY()) + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + line := buf.Lines[win.Cursor.Line] x := 0 for x < len(line) { ch := line[x] @@ -68,7 +73,7 @@ func (a MoveToLineContentStart) Execute(m action.Model) tea.Cmd { x-- } - m.SetCursorX(x) + win.SetCursorCol(x) return nil } @@ -80,11 +85,13 @@ type MoveToColumn struct { } func (a MoveToColumn) Execute(m action.Model) tea.Cmd { - line := m.Line(m.CursorY()) + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + line := buf.Lines[win.Cursor.Line] col := min(a.Count-1, len(line)-1) - m.SetCursorX(col) - m.ClampCursorX() + win.SetCursorCol(col) return nil } @@ -100,22 +107,25 @@ func (a MoveToColumn) WithCount(n int) action.Action { type ScrollDownHalfPage struct{} func (a ScrollDownHalfPage) Execute(m action.Model) tea.Cmd { - viewportHeight := m.ViewPortH() + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + viewportHeight := win.Height - 2 if viewportHeight <= 0 { return nil } scroll := viewportHeight / 2 - scrollOff := m.Settings().ScrollOff + scrollOff := win.Options.ScrollOff // Current relative position in viewport - relY := m.CursorY() - m.ScrollY() + relY := win.Cursor.Line - win.ScrollY // Scroll down, clamped to valid range - newScrollY := m.ScrollY() + scroll - maxScroll := max(0, m.LineCount()-viewportHeight) + newScrollY := win.ScrollY + scroll + maxScroll := max(0, buf.LineCount()-viewportHeight) newScrollY = min(newScrollY, maxScroll) - m.SetScrollY(newScrollY) + win.SetScrollY(newScrollY) // Maintain relative position, respecting scrollOff if relY < scrollOff { @@ -126,9 +136,8 @@ func (a ScrollDownHalfPage) Execute(m action.Model) tea.Cmd { } newCursorY := newScrollY + relY - newCursorY = max(0, min(newCursorY, m.LineCount()-1)) - m.SetCursorY(newCursorY) - m.ClampCursorX() + newCursorY = max(0, min(newCursorY, buf.LineCount()-1)) + win.SetCursorLine(newCursorY) return nil } @@ -139,20 +148,23 @@ func (a ScrollDownHalfPage) Type() action.MotionType { return action.Linewise } type ScrollUpHalfPage struct{} func (a ScrollUpHalfPage) Execute(m action.Model) tea.Cmd { - viewportHeight := m.ViewPortH() + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + viewportHeight := win.Height - 2 if viewportHeight <= 0 { return nil } scroll := viewportHeight / 2 - scrollOff := m.Settings().ScrollOff + scrollOff := win.Options.ScrollOff // Current relative position in viewport - relY := m.CursorY() - m.ScrollY() + relY := win.Cursor.Line - win.ScrollY // Scroll up, clamped to valid range - newScrollY := m.ScrollY() - scroll + newScrollY := win.ScrollY - scroll newScrollY = max(0, newScrollY) - m.SetScrollY(newScrollY) + win.SetScrollY(newScrollY) // Maintain relative position, respecting scrollOff if relY < scrollOff { @@ -163,9 +175,8 @@ func (a ScrollUpHalfPage) Execute(m action.Model) tea.Cmd { } newCursorY := newScrollY + relY - newCursorY = max(0, min(newCursorY, m.LineCount()-1)) - m.SetCursorY(newCursorY) - m.ClampCursorX() + newCursorY = max(0, min(newCursorY, buf.LineCount()-1)) + win.SetCursorLine(newCursorY) return nil } diff --git a/internal/motion/word.go b/internal/motion/word.go index 1c40bfb..332c855 100644 --- a/internal/motion/word.go +++ b/internal/motion/word.go @@ -16,8 +16,8 @@ func isWordPunctuation(c byte) bool { return c != ' ' && c != '\t' && !isWordChar(c) } -func nextWordStart(m action.Model, x, y int) (int, int) { - line := m.Line(y) +func nextWordStart(buf *action.Buffer, x, y int) (int, int) { + line := buf.Lines[y] // Skip current class if x < len(line) { @@ -46,13 +46,13 @@ func nextWordStart(m action.Model, x, y int) (int, int) { } // If next line is the end of the file, exit now - if y+1 >= m.LineCount() { + if y+1 >= buf.LineCount() { return x, y } // Move to first char of next line y++ - line = m.Line(y) + line = buf.Lines[y] x = 0 // If the first char of the new line is no whitespace, stay here! @@ -64,8 +64,8 @@ func nextWordStart(m action.Model, x, y int) (int, int) { return x, y } -func nextWORDStart(m action.Model, x, y int) (int, int) { - line := m.Line(y) +func nextWORDStart(buf *action.Buffer, x, y int) (int, int) { + line := buf.Lines[y] // Skip current WORD (all non-whitespace is one class for W) for x < len(line) && line[x] != ' ' && line[x] != '\t' { @@ -85,13 +85,13 @@ func nextWORDStart(m action.Model, x, y int) (int, int) { } // If next line is the end of the file, exit now - if y+1 >= m.LineCount() { + if y+1 >= buf.LineCount() { return x, y } // Move to first char of next line y++ - line = m.Line(y) + line = buf.Lines[y] x = 0 // If the first char of the new line is no whitespace, stay here! @@ -103,21 +103,21 @@ func nextWORDStart(m action.Model, x, y int) (int, int) { return x, y } -func nextWordEnd(m action.Model, x, y int) (int, int) { - line := m.Line(y) +func nextWordEnd(buf *action.Buffer, x, y int) (int, int) { + line := buf.Lines[y] // Advance once to avoid being stuck on the current end x++ if x >= len(line) { // At last line of file, pin cursor to end of file - if y+1 >= m.LineCount() { + if y+1 >= buf.LineCount() { return len(line) - 1, y } // Otherwise, move to next line y++ x = 0 - line = m.Line(y) + line = buf.Lines[y] } // Skip whitespace and cross lines if needed @@ -133,13 +133,13 @@ func nextWordEnd(m action.Model, x, y int) (int, int) { } // If next line is the end of the file, exit now - if y+1 >= m.LineCount() { + if y+1 >= buf.LineCount() { return x, y } // Move to first char of next line y++ - line = m.Line(y) + line = buf.Lines[y] x = 0 } @@ -160,21 +160,21 @@ func nextWordEnd(m action.Model, x, y int) (int, int) { return x, y } -func nextWORDEnd(m action.Model, x, y int) (int, int) { - line := m.Line(y) +func nextWORDEnd(buf *action.Buffer, x, y int) (int, int) { + line := buf.Lines[y] // Advance once to avoid being stuck on the current end x++ if x >= len(line) { // At last line of file, pin cursor to end of file - if y+1 >= m.LineCount() { + if y+1 >= buf.LineCount() { return len(line) - 1, y } // Otherwise, move to next line y++ x = 0 - line = m.Line(y) + line = buf.Lines[y] } // Skip whitespace and cross lines if needed @@ -190,13 +190,13 @@ func nextWORDEnd(m action.Model, x, y int) (int, int) { } // If next line is the end of the file, exit now - if y+1 >= m.LineCount() { + if y+1 >= buf.LineCount() { return x, y } // Move to first char of next line y++ - line = m.Line(y) + line = buf.Lines[y] x = 0 } @@ -208,8 +208,8 @@ func nextWORDEnd(m action.Model, x, y int) (int, int) { return x, y } -func prevWordStart(m action.Model, x, y int) (int, int) { - line := m.Line(y) +func prevWordStart(buf *action.Buffer, x, y int) (int, int) { + line := buf.Lines[y] // Back one to avoid being stuck on the current start x-- @@ -218,7 +218,7 @@ func prevWordStart(m action.Model, x, y int) (int, int) { return 0, 0 // beginning of file, stay put } y-- - line = m.Line(y) + line = buf.Lines[y] x = len(line) - 1 if x < 0 { return 0, y // landed on an empty line @@ -237,7 +237,7 @@ func prevWordStart(m action.Model, x, y int) (int, int) { return 0, 0 } y-- - line = m.Line(y) + line = buf.Lines[y] x = len(line) - 1 if len(line) == 0 { return 0, y // empty line acts as a word boundary @@ -264,13 +264,16 @@ type MoveForwardWord struct { } func (a MoveForwardWord) Execute(m action.Model) tea.Cmd { - x := m.CursorX() - y := m.CursorY() + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + x := win.Cursor.Col + y := win.Cursor.Line for i := 0; i < a.Count; i++ { - x, y = nextWordStart(m, x, y) + x, y = nextWordStart(buf, x, y) } - m.SetCursorX(x) - m.SetCursorY(y) + win.SetCursorCol(x) + win.SetCursorLine(y) return nil } @@ -286,13 +289,16 @@ type MoveForwardWORD struct { } func (a MoveForwardWORD) Execute(m action.Model) tea.Cmd { - x := m.CursorX() - y := m.CursorY() + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + x := win.Cursor.Col + y := win.Cursor.Line for i := 0; i < a.Count; i++ { - x, y = nextWORDStart(m, x, y) + x, y = nextWORDStart(buf, x, y) } - m.SetCursorX(x) - m.SetCursorY(y) + win.SetCursorCol(x) + win.SetCursorLine(y) return nil } @@ -308,13 +314,16 @@ type MoveForwardWordEnd struct { } func (a MoveForwardWordEnd) Execute(m action.Model) tea.Cmd { - x := m.CursorX() - y := m.CursorY() + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + x := win.Cursor.Col + y := win.Cursor.Line for i := 0; i < a.Count; i++ { - x, y = nextWordEnd(m, x, y) + x, y = nextWordEnd(buf, x, y) } - m.SetCursorX(x) - m.SetCursorY(y) + win.SetCursorCol(x) + win.SetCursorLine(y) return nil } @@ -330,13 +339,16 @@ type MoveForwardWORDEnd struct { } func (a MoveForwardWORDEnd) Execute(m action.Model) tea.Cmd { - x := m.CursorX() - y := m.CursorY() + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + x := win.Cursor.Col + y := win.Cursor.Line for i := 0; i < a.Count; i++ { - x, y = nextWORDEnd(m, x, y) + x, y = nextWORDEnd(buf, x, y) } - m.SetCursorX(x) - m.SetCursorY(y) + win.SetCursorCol(x) + win.SetCursorLine(y) return nil } @@ -352,13 +364,16 @@ type MoveBackwardWord struct { } func (a MoveBackwardWord) Execute(m action.Model) tea.Cmd { - x := m.CursorX() - y := m.CursorY() + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + x := win.Cursor.Col + y := win.Cursor.Line for i := 0; i < a.Count; i++ { - x, y = prevWordStart(m, x, y) + x, y = prevWordStart(buf, x, y) } - m.SetCursorX(x) - m.SetCursorY(y) + win.SetCursorCol(x) + win.SetCursorLine(y) return nil } diff --git a/internal/operator/change.go b/internal/operator/change.go index 8a8c69f..18960e1 100644 --- a/internal/operator/change.go +++ b/internal/operator/change.go @@ -58,21 +58,24 @@ func changeNormalMode(m action.Model, start, end action.Position, mtype action.M } func changeCharSelection(m action.Model, start, end action.Position) { + win := m.ActiveWindow() + buf := m.ActiveBuffer() + var deletedText string if start.Line == end.Line { - line := m.Line(start.Line) + line := buf.Lines[start.Line] endCol := min(end.Col+1, len(line)) deletedText = line[start.Col:endCol] - m.SetLine(start.Line, line[:start.Col]+line[endCol:]) + buf.SetLine(start.Line, line[:start.Col]+line[endCol:]) } else { - startLine := m.Line(start.Line) - endLine := m.Line(end.Line) + startLine := buf.Lines[start.Line] + endLine := buf.Lines[end.Line] // Extract deleted text deletedText = startLine[start.Col:] + "\n" for y := start.Line + 1; y < end.Line; y++ { - deletedText += m.Line(y) + "\n" + deletedText += buf.Lines[y] + "\n" } endCol := min(end.Col+1, len(endLine)) deletedText += endLine[:endCol] @@ -85,14 +88,13 @@ func changeCharSelection(m action.Model, start, end action.Position) { // Delete from end back to start to preserve indices for i := end.Line; i >= start.Line; i-- { - m.DeleteLine(i) + buf.DeleteLine(i) } - m.InsertLine(start.Line, prefix+suffix) + buf.InsertLine(start.Line, prefix+suffix) } - m.SetCursorY(start.Line) - m.SetCursorX(start.Col) - m.ClampCursorX() + win.SetCursorLine(start.Line) + win.SetCursorCol(start.Col) m.SetMode(action.InsertMode) // Update register with deleted text @@ -100,19 +102,22 @@ func changeCharSelection(m action.Model, start, end action.Position) { } func changeLineSelection(m action.Model, start, end action.Position) { + win := m.ActiveWindow() + buf := m.ActiveBuffer() + var lines []string for i := end.Line; i >= start.Line; i-- { - lines = append([]string{m.Line(i)}, lines...) - m.DeleteLine(i) + lines = append([]string{buf.Lines[i]}, lines...) + buf.DeleteLine(i) } // Insert an empty line for editing - insertY := min(start.Line, m.LineCount()) - m.InsertLine(insertY, "") + insertY := min(start.Line, buf.LineCount()) + buf.InsertLine(insertY, "") - m.SetCursorY(insertY) - m.SetCursorX(0) + win.SetCursorLine(insertY) + win.SetCursorCol(0) m.SetMode(action.InsertMode) // Update registers @@ -120,21 +125,23 @@ func changeLineSelection(m action.Model, start, end action.Position) { } func changeBlockSelection(m action.Model, start, end action.Position) { + win := m.ActiveWindow() + buf := m.ActiveBuffer() + startCol := min(start.Col, end.Col) endCol := max(start.Col, end.Col) for y := start.Line; y <= end.Line; y++ { - line := m.Line(y) + line := buf.Lines[y] if startCol >= len(line) { continue } ec := min(endCol+1, len(line)) - m.SetLine(y, line[:startCol]+line[ec:]) + buf.SetLine(y, line[:startCol]+line[ec:]) } - m.SetCursorY(start.Line) - m.SetCursorX(startCol) - m.ClampCursorX() + win.SetCursorLine(start.Line) + win.SetCursorCol(startCol) m.SetMode(action.InsertMode) } @@ -143,17 +150,20 @@ var _ action.DoublePresser = ChangeOperator{} // Double press handles cc - change the entire line func (o ChangeOperator) DoublePress(m action.Model, count int) tea.Cmd { - startY := m.CursorY() + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + startY := win.Cursor.Line // If we have a higher value than lines remaining, we can only run so many times - opCount := min(count, m.LineCount()-startY) + opCount := min(count, buf.LineCount()-startY) var lines []string // Collect lines to delete (always delete at startY since lines shift up) for range opCount { - lines = append(lines, m.Line(startY)) - m.DeleteLine(startY) + lines = append(lines, buf.Lines[startY]) + buf.DeleteLine(startY) } // Put deleted lines in register @@ -161,12 +171,12 @@ func (o ChangeOperator) DoublePress(m action.Model, count int) tea.Cmd { // Insert empty line at the original position for editing // If we deleted everything, startY might be past end, so clamp it - insertY := min(startY, m.LineCount()) - m.InsertLine(insertY, "") + insertY := min(startY, buf.LineCount()) + buf.InsertLine(insertY, "") // Position cursor on the new empty line - m.SetCursorY(insertY) - m.SetCursorX(0) + win.SetCursorLine(insertY) + win.SetCursorCol(0) m.SetMode(action.InsertMode) return nil diff --git a/internal/operator/delete.go b/internal/operator/delete.go index 1b120e1..5a00481 100644 --- a/internal/operator/delete.go +++ b/internal/operator/delete.go @@ -27,27 +27,29 @@ var _ action.DoublePresser = DeleteOperator{} // Double press handles dd - delete the entire line func (o DeleteOperator) DoublePress(m action.Model, count int) tea.Cmd { + win := m.ActiveWindow() + buf := m.ActiveBuffer() + // If we have a higher value than lines remaining, we can only run so many times - opCount := min(count, m.LineCount()-m.CursorY()) + opCount := min(count, buf.LineCount()-win.Cursor.Line) var lines []string for range opCount { - y := m.CursorY() - lines = append(lines, m.Line(y)) + y := win.Cursor.Line + lines = append(lines, buf.Lines[y]) - m.DeleteLine(y) + buf.DeleteLine(y) - if m.LineCount() == 0 { - m.InsertLine(0, "") + if buf.LineCount() == 0 { + buf.InsertLine(0, "") } - if y >= m.LineCount() { - y = m.LineCount() - 1 + if y >= buf.LineCount() { + y = buf.LineCount() - 1 } - m.SetCursorY(y) - m.ClampCursorX() + win.SetCursorLine(y) } // Put her in the register! @@ -89,13 +91,16 @@ func deleteNormalMode(m action.Model, start, end action.Position, mtype action.M } func deleteCharSelection(m action.Model, start, end action.Position) { + win := m.ActiveWindow() + buf := m.ActiveBuffer() + if start.Line == end.Line { - line := m.Line(start.Line) + line := buf.Lines[start.Line] endCol := min(end.Col+1, len(line)) - m.SetLine(start.Line, line[:start.Col]+line[endCol:]) + buf.SetLine(start.Line, line[:start.Col]+line[endCol:]) } else { - startLine := m.Line(start.Line) - endLine := m.Line(end.Line) + startLine := buf.Lines[start.Line] + endLine := buf.Lines[end.Line] prefix := startLine[:start.Col] suffix := "" @@ -105,54 +110,57 @@ func deleteCharSelection(m action.Model, start, end action.Position) { // Delete from end back to start to preserve indices for i := end.Line; i >= start.Line; i-- { - m.DeleteLine(i) + buf.DeleteLine(i) } - m.InsertLine(start.Line, prefix+suffix) + buf.InsertLine(start.Line, prefix+suffix) } - m.SetCursorY(start.Line) - m.SetCursorX(start.Col) - m.ClampCursorX() + win.SetCursorLine(start.Line) + win.SetCursorCol(start.Col) } func deleteLineSelection(m action.Model, start, end action.Position) { + win := m.ActiveWindow() + buf := m.ActiveBuffer() + var lines []string for i := end.Line; i >= start.Line; i-- { - lines = append(lines, m.Line(i)) - m.DeleteLine(i) + lines = append(lines, buf.Lines[i]) + buf.DeleteLine(i) } - if m.LineCount() == 0 { - m.InsertLine(0, "") + if buf.LineCount() == 0 { + buf.InsertLine(0, "") } y := start.Line - if y >= m.LineCount() { - y = m.LineCount() - 1 + if y >= buf.LineCount() { + y = buf.LineCount() - 1 } - m.SetCursorY(y) - m.ClampCursorX() + win.SetCursorLine(y) // Update registers m.UpdateDefaultRegister(action.LinewiseRegister, lines) } func deleteBlockSelection(m action.Model, start, end action.Position) { + win := m.ActiveWindow() + buf := m.ActiveBuffer() + startCol := min(start.Col, end.Col) endCol := max(start.Col, end.Col) for y := start.Line; y <= end.Line; y++ { - line := m.Line(y) + line := buf.Lines[y] if startCol >= len(line) { continue } ec := min(endCol+1, len(line)) - m.SetLine(y, line[:startCol]+line[ec:]) + buf.SetLine(y, line[:startCol]+line[ec:]) } - m.SetCursorY(start.Line) - m.SetCursorX(startCol) - m.ClampCursorX() + win.SetCursorLine(start.Line) + win.SetCursorCol(startCol) } diff --git a/internal/operator/yank.go b/internal/operator/yank.go index e463016..9bb949d 100644 --- a/internal/operator/yank.go +++ b/internal/operator/yank.go @@ -11,6 +11,8 @@ import ( type YankOperator struct{} func (o YankOperator) Operate(m action.Model, start, end action.Position, mtype action.MotionType) tea.Cmd { + win := m.ActiveWindow() + switch m.Mode() { case action.VisualMode: yankVisualMode(m, start, end) @@ -24,8 +26,8 @@ func (o YankOperator) Operate(m action.Model, start, end action.Position, mtype m.SetCommandError(fmt.Errorf("'y' operator not yet implemented.")) } - m.SetCursorX(start.Col) - m.SetCursorY(start.Line) + win.SetCursorCol(start.Col) + win.SetCursorLine(start.Line) return nil } @@ -33,15 +35,18 @@ func (o YankOperator) Operate(m action.Model, start, end action.Position, mtype var _ action.DoublePresser = YankOperator{} func (o YankOperator) DoublePress(m action.Model, count int) tea.Cmd { - y := m.CursorY() + win := m.ActiveWindow() + buf := m.ActiveBuffer() + + y := win.Cursor.Line // If we have a higher value than lines remaining, we can only run so many times - opCount := min(count, m.LineCount()-y) + opCount := min(count, buf.LineCount()-y) var lines []string for i := range opCount { - lines = append(lines, m.Line(y+i)) + lines = append(lines, buf.Lines[y+i]) } // Put her in the register! @@ -51,6 +56,8 @@ func (o YankOperator) DoublePress(m action.Model, count int) tea.Cmd { } func yankNormalMode(m action.Model, start, end action.Position, mtype action.MotionType) { + buf := m.ActiveBuffer() + switch { case mtype.IsCharwise(): // This shouldn't happen @@ -59,7 +66,7 @@ func yankNormalMode(m action.Model, start, end action.Position, mtype action.Mot return } - line := m.Line(start.Line) + line := buf.Lines[start.Line] startX := min(start.Col, end.Col) endX := max(start.Col, end.Col) @@ -85,12 +92,14 @@ func yankNormalMode(m action.Model, start, end action.Position, mtype action.Mot startY := min(start.Line, end.Line) endY := max(start.Line, end.Line) - cnt := m.Lines()[startY : endY+1] + cnt := buf.Lines[startY : endY+1] m.UpdateDefaultRegister(action.LinewiseRegister, cnt) } } func yankVisualMode(m action.Model, start, end action.Position) { + buf := m.ActiveBuffer() + // Normalize so start is before end if start.Line > end.Line || (start.Line == end.Line && start.Col > end.Col) { start, end = end, start @@ -98,7 +107,7 @@ func yankVisualMode(m action.Model, start, end action.Position) { // Single line selection if start.Line == end.Line { - line := m.Line(start.Line) + line := buf.Lines[start.Line] endCol := min(end.Col+1, len(line)) // +1 because visual selection is inclusive startCol := min(start.Col, len(line)) cnt := line[startCol:endCol] @@ -110,17 +119,17 @@ func yankVisualMode(m action.Model, start, end action.Position) { var content []string // First line: from start.Col to end of line - firstLine := m.Line(start.Line) + firstLine := buf.Lines[start.Line] startCol := min(start.Col, len(firstLine)) content = append(content, firstLine[startCol:]) // Middle lines: entire lines for y := start.Line + 1; y < end.Line; y++ { - content = append(content, m.Line(y)) + content = append(content, buf.Lines[y]) } // Last line: from beginning to end.Col (inclusive) - lastLine := m.Line(end.Line) + lastLine := buf.Lines[end.Line] endCol := min(end.Col+1, len(lastLine)) content = append(content, lastLine[:endCol]) @@ -128,6 +137,8 @@ func yankVisualMode(m action.Model, start, end action.Position) { } func yankVisualLineMode(m action.Model, start, end action.Position) { + buf := m.ActiveBuffer() + // This shouldn't happen if start.Col != end.Col { m.SetCommandError(fmt.Errorf("Start column and end column must match for linewise yank operations.")) @@ -138,12 +149,14 @@ func yankVisualLineMode(m action.Model, start, end action.Position) { startY := min(start.Line, end.Line) endY := max(start.Line, end.Line) - cnt := m.Lines()[startY : endY+1] + cnt := buf.Lines[startY : endY+1] m.UpdateDefaultRegister(action.LinewiseRegister, cnt) } func yankVisualBlockMode(m action.Model, start, end action.Position) { + buf := m.ActiveBuffer() + // Normalize so startY <= endY and startX <= endX startY := min(start.Line, end.Line) endY := max(start.Line, end.Line) @@ -153,7 +166,7 @@ func yankVisualBlockMode(m action.Model, start, end action.Position) { var content []string for y := startY; y <= endY; y++ { - line := m.Line(y) + line := buf.Lines[y] // Handle lines shorter than the block selection if startX >= len(line) {