Skip to content

fix(tui): handle spacebar in turn-running input viewport#154

Merged
Desperado merged 1 commit into
mainfrom
fix/turn-viewport-space-key
Jul 22, 2026
Merged

fix(tui): handle spacebar in turn-running input viewport#154
Desperado merged 1 commit into
mainfrom
fix/turn-viewport-space-key

Conversation

@Desperado

Copy link
Copy Markdown
Contributor

Problem

When the agent is processing a task and the user types a new message in the chat terminal, spaces are silently dropped — the message appears without spaces (e.g. helloworld instead of hello world).

Root cause

Bubble Tea v1.3.10 delivers the spacebar as tea.KeySpace, not tea.KeyRunes (bubbletea/key.go:699-701):

if len(runes) == 1 && runes[0] == ' ' {
    k.Type = KeySpace
}

The idle input widget (input.go:289) already handles tea.KeySpace correctly. But the turn-running viewport (turnViewportModel.updateKey) had no case tea.KeySpace — every space fell through to the default return m, nil and was dropped.

Fix

Added the missing case tea.KeySpace handler in turn_viewport.go that inserts ' ' at the cursor position, matching the rune-insert pattern used by the rest of the switch.

Test

Added regression test TestTurnViewportInsertsSpaceKey — verified it fails without the fix (text = "helloworld") and passes with it (text = "hello world").

=== RUN   TestTurnViewportInsertsSpaceKey
--- PASS: TestTurnViewportInsertsSpaceKey (0.00s)

All existing TestTurnViewport* tests still pass.

Bubble Tea delivers the spacebar as tea.KeySpace, not tea.KeyRunes.
turnViewportModel.updateKey had no case for tea.KeySpace, so every
space typed while the agent was processing was silently dropped —
messages appeared without spaces. Added the missing handler that
inserts a space at the cursor, matching the idle input widget
(input.go) which already handled it correctly. Regression test
included.
@sigilix

sigilix Bot commented Jul 22, 2026

Copy link
Copy Markdown

Sigilix Overview

Effort: 2/5 (small)

Quality gates

  • ✅ PR title follows convention
  • ✅ PR description is complete
  • ℹ️ PR is linked to an issue — No Closes #N / Closes SIG-N keyword found in PR body or commit messages.

Summary — latest push

Fixes a bug where spacebar input was silently dropped in the turn-running viewport by adding a missing tea.KeySpace case that inserts a space character at the cursor. The implementation correctly mirrors the existing rune-insertion pattern used for other characters, and a targeted regression test validates the fix.

Important files

File Score Notes Next step
internal/tui/turn_viewport.go 4/5 Adds the missing tea.KeySpace handler to updateKey so spacebar presses insert a space rune at the cursor instead of falling through to the default no-op return. Extract the shared slice-shift-and-insert logic used here and in tea.KeyRunes into a helper method to eliminate the copy-paste mutation pattern.
internal/tui/turn_viewport_test.go 3/5 Adds a regression test verifying that tea.KeySpace followed by tea.KeyRunes produces the expected spaced string instead of concatenated output. Add a test case for inserting a space in the middle of existing text to ensure the cursor and slice copy logic hold for non-append positions.

Confidence: 5/5

The change is a narrow, well-tested bug fix that aligns exactly with the existing input-handling pattern and carries zero risk of data corruption or side effects.

  • Verify the slice-shift logic in turn_viewport.go lines 239-241 correctly handles mid-string space insertion, not just appends, since copy behavior differs when m.cursor < len(m.text).
  • Confirm that tea.KeySpace is the only key type Bubble Tea remaps from tea.KeyRunes that this switch is missing (e.g., no other whitespace keys like tab are affected).

Suggested labels: bug


Posted · 2871401 · 0 findings — View review
Dismiss @sigilix dismiss <reason> (not-a-bug | bad-anchor | already-covered | too-minor | wrong-context) · Re-run /sigilix review
Sigilix · 0 of 50 reviews used in past 5h

@sigilix sigilix Bot added the bug Something isn't working label Jul 22, 2026
@qualitymaxapp

qualitymaxapp Bot commented Jul 22, 2026

Copy link
Copy Markdown

❌ QualityMax Pipeline

Gate Result
🔍 AI diff review ⏭️ Skipped — disabled · skipped · 0 eligible / 0 reviewed · disabled by project configuration
🔍 SAST skipped · 0 eligible / 0 reviewed · disabled by project configuration
🧪 Repo Tests ❌ 489/490 passed (go)
🤖 AI Tests ✅ 47/51 passed

Powered by QualityMax — AI-Powered Test Automation

@Desperado
Desperado merged commit 8f52196 into main Jul 22, 2026
4 of 7 checks passed
@Desperado
Desperado deleted the fix/turn-viewport-space-key branch July 22, 2026 21:47
@sigilix sigilix Bot mentioned this pull request Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant