Skip to content

mecatui: click-to-position caret in prompt textarea #490

Closed

Description

@jbeda

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:

  1. 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 like graphemeColForCellX in cmd/mecatui/ui/selection.go). Risk: a one-line disagreement with bubbles lands the caret on the wrong row — cosmetic, not a correctness failure.
  2. 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 from chrome().
  • A new branch in onMousePress AFTER the selectable path: when screenToContent returns ok=false, hit-test the input region; on hit, position the caret (CursorUp/Down to the row + SetCursorColumn) and m.ta.Focus().
  • Gate like pasteGateOpen (not during approval/overlays, where the textarea is blurred anyway).
  • Extend MECATUI_DEBUG_MOUSE to 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

  1. added
    enhancement
    tui
    fit-and-finish
    on Aug 12, 2026
  2. self-assigned this
    on Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementfit-and-finishtui

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions