Issue for this PR
Follow-up to #59209: selecting just the second of two equally labeled pastes still copies the first paste.
Type of change
What does this PR do?
The textarea highlights the correct label, but searching that substring for the first matching label loses the paste’s position. For a selection inside the prompt, expand only the tracked paste ranges fully inside the native selection. A clipped label or a lookalike typed by hand copies literally.
How did you verify your code works?
Selected cells [19,36) in a native textarea and pressed Ctrl+C. Dev wrote the four lines starting with cedar; this change wrote the selected four lines starting with ink $$. Five of ten cases diverged on dev, and all ten matched on the fix.
Replay, revisions and controls
Replay script · Complete replay bundle · Visualize base / fix
Extract the bundle and run with an installed OpenCode workspace (Linux, Bun 1.4.2, OpenTUI 0.8.4) containing base and fix:
set -o pipefail
export OPENCODE_REPO=/path/to/installed/opencode
git -C "$OPENCODE_REPO" fetch origin refs/heads/dev refs/heads/fix/tui-copy-selected-paste
bash run.sh 39502786382a965ee98497c9557a0b7afe2e6f4c | cmp base.json -
bash run.sh d979d431287c502004c2008b565dd9bbe1643db6 | cmp fix.json -
Controls cover first/second paste, clipped and crossing ranges, full selection, Escape, and a literal label between two tracked pastes after a wide/combining prefix. The selected payload includes LF, dollar sequences and another label. Each receipt repeated byte-for-byte. A local merge with undo draft #63265 passed these ten cases and its eight submission cases.
The measurement ends at the synthetic clipboard callback. The heavy-workload guard deferred broad checks. Selections spanning multiple renderables still use the existing expansion path.
Screenshots / recordings

Real TUI in a terminal with the app's own X11 clipboard: two pastes with the same label, mouse-select only the second, Ctrl+C, paste and send. Left: dev copies the first paste (cedar, plum, ash, oak). Right: the fix copies the selected one (ink, moss, fern, slate). MP4
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR