Repository navigation
feat(review): select diff lines with the mouse and comment on them - #188
Merged
Merged
Conversation
…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.
…iew is not compiled
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_terminalwith 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 andReview ▾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
Review ▾are buttons. A press clears the last selection, as in a document.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 afterv. Any key or click removes the toolbar.o/O): the same drag. In the base version, notes are read-only, so it shows no toolbar.[ui] copy_on_select(default on) copies the selected lines' code when you let go, as a document does. When it is off,ycopies 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.tsx913-933,selection.removeAllRanges()). The note is created from that range (packages/review-editor/App.tsx3033-3066).CodeAnnotation.selectedTextexists but is set only by the edit-session flow (packages/ui/types.ts327-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_rangeresets 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 callsselect_rangeonce. 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, sovstill 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. Aselectionstyle in itsColors, 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_rowandEngine::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
vselection 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 nextjmoves on from there.ctrl+ngoes 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 andr, 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, syntheticMouseEvents, 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,ycopy withcopy_on_selectoff, 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).G/gg,]/[,n/N, the wheel, and a click on every row with the sticky heading included. A resize anduare each followed by a second event before a frame.xandCact on must be the viewer's file.xandCare pressed there and undone. There are also the exact cases from review, andvthenjor].mouse on;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.block.eventmouse 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.w, PageDown puts the cursor on long.txt's hunk heading.xmarks long.txt andCopens 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.