Repository navigation
feat(native): selectable text element, used by command output - #72
Conversation
Command output can now be selected and copied: drag (across wrapped lines), double-click a word, triple-click a line, shift-click to extend, Cmd+C, Cmd+A, and a context menu with Copy. A click elsewhere clears it, and the selection holds while output streams in below it. The selection rules (word and line boundaries, drag growth, copy, carrying a selection across appended or tail-truncated text) live in t3_core::text_selection; crates/app/src/selectable_text.rs maps the pointer to offsets and paints. The offscreen snapshot gains double/triple/shift/right clicks, drags, scrolls and keystrokes.
- Remap compares the selected bytes once instead of trying every line boundary; the terminal fold now reports where its text starts (origin), so a selection follows its own line when the tail drops its front, including among identical lines and mid-line cuts. - Word selection walks graphemes: marks and emoji modifiers stay with their base, and a caret never splits one. - ANSI span fills are lifted under the selection so it stays visible. - A drag held past the output scroller's edge scrolls it.
Review findings: all five fixedRebased on
Verified against the old logic: with 653ff6f's Gates are green: |
653ff6f to
dfb3045
Compare
- A line trimmed below another counts its lost start toward the tail's origin, so a selection in it survives the line above scrolling out. - Drag steps hit-test the painted layout offset by any scroll since that paint, and the release settles the endpoint.
Follow-up findings: both fixed (
|
Problem
Command output in the native transcript was drawn as styled text you could not select or copy. On the web,
CommandOutputPanel.tsxgets browser text selection for free (drag, double/triple-click, shift-click, copy), so copying a failing test line or a path from command output only worked there. Only the markdown viewer was selectable natively.Approach
crates/core/src/text_selection.rs(pure, tested): the selection model. A press places a caret or takes the word (double-click) or line (triple-click) under the pointer, and a drag or shift-click grows it from that unit at the same granularity. It also covers select all, copy extraction, and carrying a selection across a text change. Word ranges walk graphemes, so marks and emoji modifiers stay with their base character. The selection moves with its text by the number of bytes that left the front, comparing the selected bytes once, and it is dropped once that text was dropped or redrawn.crates/core/src/terminal_output.rs:terminal_output_display, the join ofterminalOutputSpansinto one text plus styled ranges. It moved out of the app'sbuild_displayso copying across styled spans can be tested. It also adds native-onlyTerminalOutputState::origin: wheretextstarts in everything folded, so a selection follows its line as the 64K tail drops its front, including among identical lines and mid-line cuts. It flows throughCommandOutput::origin.crates/app/src/selectable_text.rs:SelectableText::new(id, text).highlights(ranges), a reusable element. It takes its font, size and colour from the parent, so any row can wrap its text in it without changes to the element.selectiontoken, the same one the markdown viewer uses.cmd-c/cmd-aare bound in itsSelectableTextkey context to the sharedCopy/SelectAllactions, so the Edit menu reaches it too. With nothing selected, Copy propagates so the window's markdown selection still copies. Right-click uses the app's existing gpui-component context menu (as the terminal does): Copy (disabled when nothing is selected) and Select all. A click anywhere else clears the selection, except the click that uses or dismisses that menu..autoscroll(&ScrollHandle)), with a 33ms step timer only during that drag. The existing 2,000-span and 64K tail caps still apply. If a caller draws the text truncated, the element stays unselectable rather than selecting wrong offsets.crates/app/src/transcript/command_output.rs: the output uses the element. Nothing else changes: idle renders of the old and new builds are byte-identical.crates/app/src/snapshot.rs: the offscreen renderer gains--double-click,--triple-click,--shift-click,--right-click,--drag x1,y1,x2,y2and--keys. They replay in command-line order with--clickand feat(native): timeline minimap #71's--hoverand--scroll. This was needed for the evidence below because events posted to a real window are dropped without accessibility trust. Note: it runs on the real platform, so--keys cmd-cwould reach the system clipboard.Not in this PR: highlighting the command line (
ShellCommandBlock), adopting the element in other transcript rows, and TR-CITE.Ledger
TR-CMDOUT stays
partial. The Feature text now reads "live output stream; the output is selectable and copyable, the command line is not syntax-highlighted yet". Native addscrates/core/src/text_selection.rsandcrates/app/src/selectable_text.rs, and Issue is#64, #69. The rest of the table is only re-padded.Evidence
Tests:
t3-core text_selection::tests: word and line boundaries (spaces, punctuation, past line end, empty line, Unicode), drags both ways, word and line growth, shift-click extension, select all and char boundaries. Copy across styled spans uses the real span pipeline. Remap covers appended and redrawn-below output (kept), a redrawn selection (dropped), and a realTerminalOutputStatetail past its cap (shifted, or dropped once the selected lines scroll out).t3-native selectable_text::tests: hit-testing against constructed GPUI line layouts: nearest boundary vs character under the pointer, row edges, above/below the text, newline offsets, and wrapped rows. Selection fills cover one row, across wrapped rows, start or end at a soft wrap, across lines, and a selected newline alone.Screenshots (GPUI offscreen renderer via
--snapshotagainst the smoke server, "Native client showcase",vp test runexpanded, the same--dragreplayed on both builds; full windows areg-*.png, cropsgc-*.png), in/private/tmp/claude-501/-Volumes-DevSSD-t3code-native/15deb025-b650-4cf9-a1aa-1cc16b006f6d/scratchpad/shots69/:63cd8da):gc-before-dark.png,gc-before-light.png. The drag selects nothing.gc-after-dark.png,gc-after-light.png. The drag selects across three lines.gc-dbl.png(double-click "math"),gc-triple.png(triple-click a line),gc-shift.png(click then shift-click),gc-all.png(cmd-a),gc-dragout.png(drag ending on the row header: the row stays open),gc-away.png(click elsewhere clears),gc-menu.png/gc-after-menu-light.png(right-click: Copy ⌘C enabled, Select all ⌘A).Copy with
cmd-cwas not run against the system clipboard, to avoid overwriting the developer's clipboard. It is covered by the core copy test plus the menu showing Copy enabled for the live selection.A snapshot run that ends with a gpui-component context menu open exits non-zero at teardown ("leaked PopupMenu handle"). The PNG is written first. This is pre-existing: it reproduces with this PR's menu hook removed, and removing the window first doesn't help.
Review findings and their fixes are in the PR conversation.
Gates (from
apps/native):cargo clippy --workspace --all-targets -- -D warnings(also with--features snapshot),cargo test --workspace,node scripts/gen-theme.ts --check,node --test parity/sync.test.ts, and, frompackages/client-runtime,node ../../apps/native/conformance/generate.ts --checkall pass.Closes #69