Repository navigation
Description
Split out of #486 (mouse interactions). The first PR ships clickable approval/plan-review buttons; this is the follow-up for click-to-position-caret in the prompt textarea.
Behaviour
Clicking inside the prompt input region moves the textarea caret to the clicked cell (and focuses the textarea if it was blurred by an overlay). No word-select in the input in v1 (deliberate cut).
Why this is the hard one
The click cell must map to a (buffer row, rune column) through the bubbles textarea's SOFT WRAP. The wrap geometry lives in bubbles' unexported memoizedWrap (charm.land/bubbles/v2/textarea), which is rune-width-aware with a non-obvious trailingSpace=2 reservation. Options:
- Replicate the wrap semantics locally (accumulate visual heights per logical line at
m.ta.Width(), map visual row → logical line → rune index via a grapheme walk likegraphemeColForCellXincmd/mecatui/ui/selection.go). Risk: a one-line disagreement with bubbles lands the caret on the wrong row — cosmetic, not a correctness failure. - Upstream a
textarea.PositionAtCell(x, y)to bubbles as the real fix.
The input region's screen rect must be derived from chrome() (layout.go), never constants — same discipline as convTopRow, plus a drift test. Rail geometry from inputRailStyle(...).GetHorizontalFrameSize() (view.go:898).
Shape (from the #486 plan)
inputRegionRect(m)helper derived fromchrome().- A new branch in
onMousePressAFTER the selectable path: whenscreenToContentreturns ok=false, hit-test the input region; on hit, position the caret (CursorUp/Downto the row +SetCursorColumn) andm.ta.Focus(). - Gate like
pasteGateOpen(not during approval/overlays, where the textarea is blurred anyway). - Extend
MECATUI_DEBUG_MOUSEto print the input-region mapping for diagnosis.
Tests
textarea_click_test.go: fixed-height buffer with known content; click each visible cell → assert m.ta.Line()/m.ta.Column(); soft-wrapped long line; scrolled buffer; click in rail border/padding (clamp or no-op — decide); click past EOL → line end; empty buffer → (0,0); blurred → focus restored. Regression-run textarea_guard_test.go (the wordLeft-hang guard is untouched).
Activity