Expand description
Mouse (and keyboard-extended) text selection scoped to a single panel (Request JSON / Response).
The terminal’s own click-drag selection can’t be confined to one panel — it always spans the full terminal row, sweeping up whatever’s to the left (other panels, borders, etc.). To let users copy a long response body or URL cleanly, the app captures the mouse itself and implements its own selection: dragging inside a panel selects text using ordinary “stream” semantics (first line from the start column to its own end, full lines in between, last line from its own start to the end column) — never a rectangular block — and never anything outside that panel’s own Rect.
Selections are stored as TextPos (logical line/char-offset)
positions, not terminal (row, col) cells — see wrapcache — so the exact
same characters stay selected across a rewrap/rescroll/resize instead of
silently re-interpreting stale screen coordinates against new content.
Functions§
- extract_
text - Extract the selected text (lines joined with
\n) between two logical positions. Cost is proportional only to the selected lines themselves (viaPanelWrap::line_text’s O(1) slicing), never the panel’s total content size.Nonewhen there’s nothing to select (no content, or a purely blank selection).exclude, when given, drops any character whose position is in the set — used to keep purely-visual annotations (like the Request panel’s shadow-warning icon; seeTuiApp::main_shadow_icon_positions) out of copied text even though they’re part of what’s shown on screen. - highlight_
cells - Convert the selection into absolute terminal cell ranges (row, col_from,
col_to_exclusive) suitable for painting a highlight, for whichever
(raw) lines the selection intersects the current visible window
(
scroll..scroll + area.height). Bounded to that window — never the whole selection — so highlighting stays cheap even when the selection itself spans an enormous, mostly off-screen range. - ordered
- Order two positions so the first is not after the second (a selection dragged “backwards” — up or left — still resolves correctly).
- point_
to_ textpos - Map a raw terminal (column, row) point onto the
TextPosit corresponds to, given the panel’s Rect, its current scroll offset (in wrapped rows), and its line/wrap cache. Points outside the area clamp to its nearest edge, exactly as the on-screen content does. - strip_
positions - Strip every character at a position in
excludefromtext(used for “copy the whole panel”, which reads straight fromPanelWrap::sourcerather than going throughextract_text’s per-line ranges). Rebuilds line-by-line the same waytext’s own trailing newline was originally appended (seedraw::draw_collection_main), so a whole-panel copy still matches the underlying buffer exactly but for the excluded positions.