▍ humdrum codex / glint v1.0.2

fix: spacebar inserted two spaces (TASK-002)

2f9445843b4fa85930b19f402bd8c08d428dd79a
humdrum <me@humdrum.me> · 2026-06-28 11:22

parent 85f26129

fix: spacebar inserted two spaces (TASK-002)

Real bubbletea reports a space as KeySpace with Runes==[' '], so the
rune loop already inserts it; the extra 'if KeySpace { InsertRune(" ") }'
added a second. Drop the redundant block and make the regression test
send a realistic KeySpace msg (Runes:[' ']) — the old test missed the
bug by sending an empty-Runes message.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

2 files changed

internal/editor/editor.go +2 −3
@@ -249,11 +249,10 @@ // HandleKey maps a key message to a buffer operation.
 func (e *Editor) HandleKey(k tea.KeyMsg) {
 	switch k.Type {
 	case tea.KeyRunes, tea.KeySpace:
+		// Real bubbletea reports a space as KeySpace with Runes == [' '], so the
+		// loop already inserts it — do not add a second space here.
 		for _, r := range k.Runes {
 			e.InsertRune(r)
-		}
-		if k.Type == tea.KeySpace {
-			e.InsertRune(' ')
 		}
 	case tea.KeyEnter:
 		e.InsertNewline()
internal/editor/editor_test.go +1 −1
@@ -147,7 +147,7 @@
 func TestHandleKeySpaceInsertsSingleSpace(t *testing.T) {
 	e := newEditorWith("ab")
 	e.Cursor = Position{Row: 0, Col: 1}
-	e.HandleKey(tea.KeyMsg{Type: tea.KeySpace})
+	e.HandleKey(tea.KeyMsg{Type: tea.KeySpace, Runes: []rune{' '}})
 	if e.Lines[0] != "a b" {
 		t.Errorf("Lines[0] = %q, want 'a b'", e.Lines[0])
 	}