package editor import ( "testing" tea "github.com/charmbracelet/bubbletea" ) // --- TASK-027: mouse drag-select --- func TestMouseAnchorMovesCursorNoSelection(t *testing.T) { e := New() e.SetSize(80, 10) e.SetContent([]byte("hello world")) e.MouseExtendTo(0, 5) // pretend a stale selection exists e.MouseAnchor(0, 3) if e.HasSelection() { t.Fatal("MouseAnchor left a selection active") } if e.Cursor.Col != 3 { t.Fatalf("cursor col = %d, want 3", e.Cursor.Col) } } func TestMouseExtendCreatesSelectionFromAnchor(t *testing.T) { e := New() e.SetSize(80, 10) e.SetContent([]byte("hello world")) e.MouseAnchor(0, 2) e.MouseExtendTo(0, 7) if got := e.SelectedText(); got != "llo w" { t.Fatalf("selection = %q, want %q", got, "llo w") } } func TestMouseExtendKeepsOriginalAnchorAcrossMotions(t *testing.T) { e := New() e.SetSize(80, 10) e.SetContent([]byte("hello world")) e.MouseAnchor(0, 2) e.MouseExtendTo(0, 4) e.MouseExtendTo(0, 9) // a second drag motion must not re-anchor at col 4 if got := e.SelectedText(); got != "llo wor" { t.Fatalf("selection = %q, want %q", got, "llo wor") } } // --- TASK-023: Alt+x keybind toggles + is undoable --- func TestAltXTogglesCheckboxUndoable(t *testing.T) { e := New() e.SetContent([]byte("- [ ] task")) e.Cursor = Position{Row: 0, Col: 9} altX := tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("x"), Alt: true} e.HandleKey(altX) if got := e.Lines[0]; got != "- [x] task" { t.Fatalf("after Alt+x line = %q, want %q", got, "- [x] task") } e.Undo() if got := e.Lines[0]; got != "- [ ] task" { t.Fatalf("after undo line = %q, want %q", got, "- [ ] task") } }