feat(tui): caret editing + paste normalization across input dialogs
Summary
- Replaces the hand-rolled key handlers in all three TUI text inputs (
FirstTimeSetupPRD-name,PRDPickernew-PRD-name,BranchWarningbranch-name) withbubbles/textinput, so Left/Right/Home/End/Ctrl+Left/Ctrl+Right and clipboard paste now behave like a normal terminal input. Charset filtering, max-length caps, blink/focus wiring, and width-sync are preserved. - Adds paste normalization: runs of invalid characters in pasted text collapse to a single
-(with leading/trailing invalid runes stripped) instead of being silently dropped, so"my feature/v2!"→"my-feature-v2"and"feat/oops bad!"→"feat/oops-bad". Detected via bracketed-paste flag or multi-runeKeyRunesfallback so terminals without bracketed-paste get the same UX. Single-keystroke typing keeps the drop-based filter. - Fixes ctrl+c being swallowed in picker input mode and branch-warning edit mode (previously slipped through to the textinput and did nothing — now routes through
tryQuitjust likeFirstTimeSetup).
Scope
Implemented as a user-story series (US-001..US-009) followed by two targeted follow-ups:
| Story | Scope |
|---|---|
| US-001..US-006 | FirstTimeSetup PRD name: adopt bubbles/textinput, caret keys, paste-with-filter, max length, test matrix |
| US-007 | PRDPicker new-PRD-name: same adoption |
| US-008 | BranchWarning branch-name: same adoption |
| US-009 | Test matrix parity for picker + branch-warning |
| — | ctrl+c dispatch fix in picker + branch-warning input modes |
| US-004a | Paste normalization (interior invalid runs → -, ends stripped) |
New shared helpers in internal/tui/input_filters.go: isAllowedPRDNameRune, isAllowedBranchNameRune, isTextualKey, isPasteLike, filterRunes, normalizePastedRunes,
and the word-jump helpers (wordBackward/wordForward).
Manager.SetInstanceState added to internal/loop/manager.go so tests can force a running loop without spinning up a Provider — unblocks the ctrl+c → quit-confirm regression
tests (the previous inst := m.GetInstance(...); inst.State = ... pattern mutated a copy; see the GetInstance docstring comment "Return a copy to avoid race conditions").
New dependency: github.com/charmbracelet/bubbles (first-party charmbracelet component library, same author as bubbletea which is already a direct dependency).
Test plan
- [ ]
go test ./...passes locally. - [ ] Manual: open first-time setup, press
nnothing — type a PRD name using Left/Right/Home/End/Ctrl+Left/Ctrl+Right; caret moves as expected, invalid single keystrokes are silently dropped. - [ ] Manual: paste
"my feature/v2!"in the PRD-name field →"my-feature-v2". - [ ] Manual: in the main TUI, press
n, paste a name with invalid chars → interior runs collapse to-, trailing invalid stripped, cursor keys work. - [ ] Manual: open the branch-warning modal (trigger a protected-branch path), press
e, paste"feat/oops bad!"→"feat/oops-bad"(note/is preserved — it's in the branch charset). - [ ] Manual: ctrl+c in picker input mode with no running loop → app quits cleanly. Ctrl+C with a running loop → quit-confirmation dialog opens; Esc returns to the picker with the in-progress input preserved.
- [ ] Manual: paste >64 chars → value truncates to
maxPRDNameLength; paste >255 chars in branch-warning → truncates tomaxBranchNameLength. - [ ] Manual: typing at max length is a silent no-op (no error, value unchanged).
- [ ] Regression: existing
FirstTimeSetupflows (esc → back to gitignore step / quit, Enter → validate + advance) unchanged.
Notes for reviewer
- The CLI's
isValidPRDNameininternal/cmd/new.gois intentionally left alone — the length cap is TUI-only per US-005 Non-Goals. - Paste normalization is scoped to the pasted content; no cross-boundary dedupe against existing field text (so pasting
-xyzinto a field ending in-yields--xyz, by design — confirmed with product). go.modbumps 1.24.0 → 1.24.2 and addsbubbles; transitive charm deps shift accordingly.
🤖 Generated with Claude Code