1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
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")
}
}
|