Pad/internal/editor/buffer_test.go
Greg Pomerantz 0dac354f2a fix(editor): wire key events to cursor movement
- Replace gtx.Event(nil) with key.Filter{Focus: focusedID} and
  key.FocusFilter{Target: focusedID} so Gio correctly routes key
  and edit events to the focused editor text field.

- Convert EditorState.CursorPosition (byte offset) to line/column
  coordinates for accurate cursor rendering.

- Add debug logging in HandleKeyDown and HandleCursorMove.
2026-06-03 07:41:18 -04:00

40 lines
962 B
Go

package editor
import (
"testing"
)
func TestInsertChar(t *testing.T) {
state := NewState()
TheState = state
state.Editor.Buffer = "Hello"
state.Editor.CursorPosition = 5 // End of "Hello"
HandleInsert("!") // Assuming we create this function
expected := "Hello!"
if state.Editor.Buffer != expected {
t.Errorf("Expected buffer %q, got %q", expected, state.Editor.Buffer)
}
if state.Editor.CursorPosition != 6 {
t.Errorf("Expected cursor position 6, got %d", state.Editor.CursorPosition)
}
}
func TestBackspace(t *testing.T) {
state := NewState()
TheState = state
state.Editor.Buffer = "Hello"
state.Editor.CursorPosition = 5
HandleBackspace() // Assuming we create this function
expected := "Hell"
if state.Editor.Buffer != expected {
t.Errorf("Expected buffer %q, got %q", expected, state.Editor.Buffer)
}
if state.Editor.CursorPosition != 4 {
t.Errorf("Expected cursor position 4, got %d", state.Editor.CursorPosition)
}
}