Skip to content

Enable copy from the Review preview panel - #218

Merged
stippi merged 2 commits into
mainfrom
feature/review-panel-copy
Oct 2, 2026
Merged

stippi merged 2 commits into
mainfrom
feature/review-panel-copy

Conversation

@daniel-kurzynski

Copy link
Copy Markdown
Collaborator

What

The right-side Review diff is painted by a custom DiffRows GPUI element (raw glyph painting) inside a virtualized list, so its text wasn't selectable — you couldn't copy anything out of it (e.g. to paste a snippet into the chat).

This adds whole-line text selection to the Review diff:

  • Drag across lines to select — selection follows across a file's diff chunks.
  • Copy with Cmd/Ctrl+C (clicking a diff focuses the panel) or the Copy button that appears in the panel header while a selection exists.
  • Copied text is the plain line content (no +/- gutters), joined by newlines.

Selection is line-granular rather than character-level: it's the natural unit for grabbing code, and it keeps hit-testing and painting robust over wrapped, virtualized rows without regressing the perf-oriented DiffRows design.

How

  • tool_cards/diff_rows.rs — optional RowSelection on DiffRows: paints a selection highlight behind the glyphs (above the add/delete tint, below the text) and registers pointer listeners that map a position to a flat line index (base_line + the row under the cursor). Tool-card diffs stay non-selectable.
  • tool_cards/diff_card.rs — thread the optional selection through render_diff_chunk / render_diff_rows.
  • main_screen/right_panel/review_view.rs — hold the selection per file; begin/extend/end on pointer events via a weak entity handle (so the static element closures never borrow the view); copy the joined lines; clear the selection when the file leaves the listing or the session changes; header Copy button + Cmd/Ctrl+C on the focused panel.

Notes

  • Selection never spans files; starting a drag in another file replaces it.
  • A single click selects one line (and reveals the Copy button). Happy to change this to require an actual drag if preferred.

Tests

  • local_line y→row mapping (incl. clamping) in diff_rows.
  • Cross-chunk line joining and reversed-drag / inactive-drag behavior in review_view.
  • cargo fmt --check, cargo clippy -p ui_gpui, and cargo test -p ui_gpui (173 passed) all green.

The right-side Review diff is painted by a custom DiffRows element inside a
virtualized list, so its text was not selectable. Add whole-line selection:
drag to select lines across a file's diff chunks, then copy with Cmd/Ctrl-C or
the header Copy button (e.g. to paste code into the chat).

- diff_rows: optional RowSelection on DiffRows — paints a selection highlight
  behind the glyphs and registers pointer listeners that map a position to a
  flat line index (base_line + row under the cursor).
- diff_card: thread an optional selection through render_diff_chunk /
  render_diff_rows (tool-card diffs stay non-selectable).
- review_view: hold the selection per file, begin/extend/end on pointer events
  via a weak handle, copy the joined lines, clear it when the file leaves the
  listing or the session changes.

Tests cover the y->row mapping and cross-chunk line joining.
Reuse the review panel's selectable-rows infrastructure for the
edit/replace_in_file/write_file diff cards: drag-select whole lines,
then copy via a header Copy button or Cmd/Ctrl-C.

- BlockView owns the per-card selection (flat line indices across the
  card's diff sections) plus a focus handle for keyboard copy.
- CardRenderContext carries the focus handle and current selection range.
- render_prepared_diff/render_diff_lines thread a RowSelection per
  section, wired to the BlockView via a weak handle (mirrors ReviewView).
- Header shows a Copy button while a selection exists; the card is
  focusable and handles Cmd/Ctrl-C.
@stippi
stippi merged commit f59b81f into main Oct 2, 2026
5 checks passed
@stippi
stippi deleted the feature/review-panel-copy branch October 2, 2026 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants