chief icon indicating copy to clipboard operation
chief copied to clipboard

feat(tui): caret editing + paste normalization across input dialogs

Open Magentron opened this issue 7 months ago • 0 comments

Summary

  • Replaces the hand-rolled key handlers in all three TUI text inputs (FirstTimeSetup PRD-name, PRDPicker new-PRD-name, BranchWarning branch-name) with bubbles/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-rune KeyRunes fallback 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 tryQuit just like FirstTimeSetup).

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 n nothing — 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 to maxBranchNameLength.
  • [ ] Manual: typing at max length is a silent no-op (no error, value unchanged).
  • [ ] Regression: existing FirstTimeSetup flows (esc → back to gitignore step / quit, Enter → validate + advance) unchanged.

Notes for reviewer

  • The CLI's isValidPRDName in internal/cmd/new.go is 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 -xyz into a field ending in - yields --xyz, by design — confirmed with product).
  • go.mod bumps 1.24.0 → 1.24.2 and adds bubbles; transitive charm deps shift accordingly.

🤖 Generated with Claude Code

Magentron avatar Apr 24 '26 21:04 Magentron