Skip to content

feat(review): select diff lines with the mouse and comment on them - #188

Merged
backnotprop merged 14 commits into
mainfrom
feat/review-mouse
Nov 23, 2026
Merged

backnotprop merged 14 commits into
mainfrom
feat/review-mouse

Conversation

@backnotprop

@backnotprop backnotprop commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Commenting from the mouse in plannotator-tui review: drag over lines, then comment where you selected, as in a document review.

Why the mouse seemed dead

Mouse capture is on in the code review: it shares with_terminal with the document screen, which enables modes 1000/1002/1003 and SGR 1006. On 0.11.0 the wheel, a click on a line (and its side), a click in the file list, the rail, Send and Review ▾ already reached the app, through a plain tmux pane, a nested tmux and an isolated Rex server. What was missing was the drag. diffs-rs handles only the wheel and a left press, and the review passed drag and release events to it, where they were ignored. Pressing and dragging only moved the cursor, and mouse capture also blocks the terminal's own text selection.

What the mouse does now

  • Wheel: scrolls the diff, the file list or the notes under the pointer (as before), and the key help.
  • Click: puts the cursor on the line, on the old or new side clicked. A click in the file list opens that file, and a click on a folder opens or closes it (the list's own handling, from feat(review): a file list that fits its names, with filters by name, kind and viewed #189). A click on a note selects it and shows its lines. Send and Review ▾ are buttons. A press clears the last selection, as in a document.
  • Drag: selects whole lines on the side where it started. The lines are shaded while you drag. Past the top or bottom of the pane, each step scrolls a line. Rows with nothing on that side, or in another file, leave the range alone.
  • Release: the lines become the selection, as after v. A toolbar next to them offers 💬 comment (c) and, for new lines, ✎ suggest (s). This matches the toolbar a document shows after a mouse selection. Keys and clicks still work as they do after v. Any key or click removes the toolbar.
  • Whole-file view (o/O): the same drag. In the base version, notes are read-only, so it shows no toolbar.
  • Copy: [ui] copy_on_select (default on) copies the selected lines' code when you let go, as a document does. When it is off, y copies them and the footer says so.

How a selection is anchored

As the browser anchors it: whole lines on one side (lineStart, lineEnd, side), no schema change. In Plannotator's review editor, a text drag over diff content becomes a line range on the anchor's side, and the selected text is discarded (packages/review-editor/components/DiffViewer.tsx 913-933, selection.removeAllRanges()). The note is created from that range (packages/review-editor/App.tsx 3033-3066). CodeAnnotation.selectedText exists but is set only by the edit-session flow (packages/ui/types.ts 327-335), so it is not used here. The agent still gets the code: a line comment's feedback quotes the lines under **Highlighted text:**, as before.

How the drag works

diffs-rs has no drag and no "line under this cell". select_range resets the viewer's visible rows, so it can't run on every drag step. Each step clicks the viewer at the pressed column on the pointer's row (so a split diff keeps the pressed side) and reads the line the cursor landed on. The range is kept in the app and shown as a gutter mark until the release, which calls select_range once. The file list (#189) takes its clicks and wheel before the toolbar and before a press can start a selection; a drag that is already selecting goes on over the list. While a drag goes on, the list and the footer follow the file under the pointer, as they follow the cursor.

How a selection looks

A selection, made with v, with a drag, or in the whole-file view, is one block of background colour over the selected lines, edge to edge on their side: grey on the dark theme, the theme's light blue on the light theme. Both are different from the added and removed tints, and syntax colours stay as they are. There is no gutter bar and no underline. The cursor's line keeps its accent line number, so v still shows which end moves.

That style comes from diffs-rs (render.rs, code()): a selected line gets a bold accent ┃ in its first cell and underlined text; the cursor's row gets the thinner ▎ instead (the cursor wins) and accent line numbers. diffs-rs 0.2.1 has no style setting for any of this, so the app fixes it after the viewer draws. A pass over the drawn rows finds each pane whose first cell holds that bar or the drag's mark, blanks the cell, takes the underline off (a search match is bold as well, and keeps its underline), and fills the pane to the split's middle line (at (width - 1) / 2, as diffs-rs places it) or the pane's edge. No change to diffs-rs is needed. A selection style in its Colors, used instead of the bar and the underline, would make the pass unnecessary.

Which file the cursor is in

x, C, n/N, ctrl+n, the file list's highlight and the footer's path all need the file the cursor is in, on every kind of row (a heading, a hunk heading, a gap, a binary file's note). diffs-rs 0.2.1 only reports a line under the cursor. An earlier version of this PR worked the file out from the moves it sent, and it was wrong after wrapped page moves, the wheel near a heading, a click on the sticky heading, and two events before a frame.

diffs-rs now reports the cursor's row and the row at a screen cell: Engine::cursor_row and Engine::row_at, in plannotator/diffs-rs#15. The review asks it every time. Nothing about the position is kept between events and frames, and the list and the footer copy the answer after every event and before every frame. The review depends on diffs-rs 0.2.2 from crates.io, which has both.

A v selection grows only inside the hunk it started in, as a drag does. A step past the hunk's edge brings the cursor back to the edge line. A jump to another hunk or file (], n) ends the growing, so the next j moves on from there.

ctrl+n goes by the viewer's file index and passes over every file of the path the cursor is on, so a symlink deleted and a file added in its place (two files, one path) no longer bring it back to the same file.

A panic now turns off mouse capture, focus reports, bracketed paste and the keyboard flags before ratatui's hook gives the screen back. The hook is in place before any of them is turned on.

Resizing the panes

Drag the line between the file list and the diff, or between the diff and the notes panel (now drawn as a line too), to resize the list or the notes. The line lights up under the pointer and while you drag it. A double click on a line lets the pane fit itself again. A press on a line never moves the cursor or starts a selection.

The list uses the same width as </>; the notes get the same thing with new keys {/} (widen-notes/narrow-notes), in the keymap, help, footer and README. A width set by drag or key stays for the rest of the review, through filters and r, and auto-fit stops overriding it; the diff keeps its minimum width (48 columns), and the list its narrowest when it shows.

Tested

  • review/tests/divider_mouse.rs (5 tests): resizing by drag and key, the limits, staying through a filter and a reload, double click, the light-up cue, and no cursor move or selection from a press on a line.
  • review/tests/mouse_flow.rs (15 tests, synthetic MouseEvents, positions found in the drawn frame): drag on new and old side, dragging up, a click without a selection, a new press clearing a selection, shading, the toolbar, keys removing it, y copy with copy_on_select off, scrolling past the bottom, the whole-file view, the wheel, the file list, a rail note, Send and Review.
  • review/tests/place_flow.rs: a review with every kind of file (a binary file first, a mode-only change, a rename, a deleted file, a new file, a very long file, a symlink replaced by a file, a very wide line, no newline at the end).
    • Coverage: unified and split, wrapped or not, at 110x18 and 170x30. The moves are every row down and up, page moves, G/gg, ]/[, n/N, the wheel, and a click on every row with the sticky heading included. A resize and u are each followed by a second event before a frame.
    • Checks: after every event, the list's file and the file x and C act on must be the viewer's file. x and C are pressed there and undone. There are also the exact cases from review, and v then j or ].
  • Real mouse input (SGR bytes, not synthetic events), against the built binary:
    • written to the pane of a tmux server with mouse on;
    • typed into the client of an inner tmux server (mouse on) attached in an outer tmux pane, so the inner tmux routed and re-encoded every press, drag, release and wheel event. Drag, comment, save and Send gave ### Lines 16-20 (new) with those lines quoted in the delivered feedback. Unified view and the whole-file view were included.
    • Rex's own block.event mouse and wheel events, in an isolated Rex server (its own socket, state and config): a click, the wheel and a drag (press, motion with the button held, release) all reached the app.
  • cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace, and the review tests 20 times in a row.
  • In the built binary in tmux at 120x40, with a binary file first and short files before a long file: w, PageDown puts the cursor on long.txt's hunk heading. x marks long.txt and C opens a note on long.txt; the previous commit of this branch marks and notes aa.bin.

Not tested: a mouse in a GUI terminal window (Rex.app, Herdr or a terminal emulator), and Herdr at all.

…a comment

A drag in the diff or the whole-file view selects whole lines on the side it
started on, as the browser's code review anchors them. The lines are shaded
while dragging, dragging past the pane's edge scrolls, and the release makes
them the selection with a comment/suggest toolbar beside it. copy_on_select
copies the lines on release; when it is off, y copies them. The wheel scrolls
the key help.

diffs-rs has clicks and the wheel but no drag, so each drag step clicks the
viewer at the pressed column and reads the line the cursor landed on.
… or the underline

diffs-rs marks selected lines with a bar in the first cell, which turns into the cursor's
thinner bar on the cursor's row, and underlines their text. The pass over the drawn rows
now blanks that cell, takes the underline off, and fills each selected pane to its end,
the split's middle line or the pane's edge. The keyboard's v selection, a drag and the
whole-file view all look the same: grey on dark, the theme's light blue on light.
The file list now takes its clicks and wheel before the toolbar and before a press starts
a line selection; a drag already selecting goes on over it. The footer's selection label
and copy hints move to footer.rs. The current file is not looked for mid-drag, where its
key presses could scroll the rows under the pointer; the release finds it.
…t and the notes

The line right of the file list and a new one left of the notes panel take presses
before anything else in the review: a drag resizes the pane, a double click fits it
again, and the line lights up under the pointer and while dragged. A press on a line
never moves the cursor or starts a selection. The width uses the same state as < and
>, so it stays through filters and reloads and auto-fit stops overriding it; the diff
keeps its minimum. { and } (widen-notes, narrow-notes) resize the notes by keys.
Bold made terminals draw the line with a shorter glyph, so a lit line broke into dashes
while the unlit one stayed solid.
In the unified view a removed line sits among the new lines a selection covers, and
was left unshaded, so the selection read as two blocks. Rows strictly between the first
and the last selected row now take the selection colour too. Only the look changes: the
note covers and quotes the selected side's lines alone.
- A release over lines no longer shown (another view, a reloaded or
  filtered diff) selects nothing and says so. No mouse event can end
  the review: an error is said in the footer.
- One place drops a drag of lines or of a pane's edge, its shading with
  it: a key, a paste, a resize, focus lost, a second press, a move with
  no button held, or any mouse event outside Browse. Focus change
  reporting is on so a release outside the window is noticed.
- A drag and a growing `v` selection stay in the hunk they started in.
  The shading between selected rows skips headings and gaps.
- Which file and row the cursor is on is worked out from the viewer's
  own row layout and the last frame, without pressing keys: `v` no
  longer grows by itself, `n`/`N` put the heading on the top row, and
  a click on a heading scrolls nothing.
- Configs that set `copy` keep it on the document screen: the code
  review copies with its own `copy-lines` action, which takes `copy`'s
  keys when only `copy` is set.
- A double click on a pane's edge needs two clicks on one cell without
  a move. A width chosen for the list or the notes stays the choice
  through a narrower window.
- The toolbar ignores clicks beside its buttons and never covers a
  selected row; after a drag up the view stays put on release, and a
  shift-click grows from the line first pressed. The split's middle is
  found by geometry, so a bar in the code no longer cuts the shading.
Comment takes the document toolbar's comment colour, suggest its own
256-colour pair, and both join the contrast test in ui::chips.
…ng it

The code review worked out which file the cursor was in from the moves it sent the
viewer. With wrapping on, after a page move, after the wheel near a heading, after a
click on the sticky heading and when two events came before a frame, that guess named
the wrong file, so x, C, n and N and ctrl+n acted on it and the list and the footer
showed it.

diffs-rs now says which row the cursor is on, on every kind of row, and which row is
drawn at a screen cell (plannotator/diffs-rs#15). The review asks it every time: the
move model and the per-file row projection are gone, and nothing about the position is
kept between events and frames. The list and the footer copy the answer after every
event and before every frame. A selection kept to its hunk now asks the viewer which hunk
the cursor is in, so a jump to the next hunk ends the growing and j moves on from there.

Until diffs-rs publishes the new API, it comes from the branch by [patch.crates-io].

A panic now turns off mouse capture, focus reports, bracketed paste and the keyboard
flags before ratatui's hook gives the screen back.
…files

- Depend on diffs-rs 0.2.2, which has Engine::cursor_row and Engine::row_at, instead of the
  branch by [patch.crates-io].
- ctrl+n goes by the viewer's file index and passes over every file of the path the cursor
  is on, so a symlink deleted and a file added in its place no longer bring it back to the
  same file. The count of files not viewed counts each path once.
- The panic hook that turns the input modes off is in place before mouse capture or any
  other mode is on.
@backnotprop
backnotprop added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit c63c254 Nov 23, 2026
3 checks passed
@backnotprop
backnotprop deleted the feat/review-mouse branch November 23, 2026 22:31
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.

1 participant