Skip to content

fix(review): a drag selection no longer races the diff to the bottom - #193

Merged
backnotprop merged 2 commits into
mainfrom
fix/drag-scroll
Nov 24, 2026
Merged

backnotprop merged 2 commits into
mainfrom
fix/drag-scroll

Conversation

@backnotprop

@backnotprop backnotprop commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Reported from a terminal in a window (Rex, possibly Herdr): "whenever I select text, it all just scrolls to the bottom." This fixes the code review (plannotator-tui review) and the document screen (files, folders and agent replies).

Cause

review/mouse.rs drag_to (v0.11.1, lines 188-191) ran Command::Up or Command::Down for every drag report whose row was above or below the diff pane:

  • No limit on the rate. A terminal in a window can send a report for every pixel the pointer moves, and many reports for one cell. The Herdr app encodes mouse input with libghostty-vt and does not set GHOSTTY_MOUSE_ENCODER_OPT_TRACK_LAST_CELL, so it does this. Our tmux tests sent one report per cell, with a frame between reports, so they did not show it.
  • No stop at the hunk. The selection is clamped to the anchor's hunk, but the cursor went on moving, so the view went through the next files to the end of the diff.
  • Stale frame. The review loop handles all pending events before it draws. After a scroll step, the next click in the same burst was hit-tested against the old frame (Engine::row_at and clicks use the last drawn frame). So a burst ended on other lines than the same reports one per frame: 12..18 against 12..28 in the new test.

A drag that stays inside the pane did not scroll in v0.11.1, in bursts too. This was checked in a test and in the release binary.

Reproduction (v0.11.1 release binary, private tmux, 160x45)

Four files of 200 lines, each changed in blocks (first hunk: new lines 1..92). All reports were sent in one send-keys -l string:

Step v0.11.1 this branch
press on line 20 in the middle, 40 drag reports over 8 rows (5 per cell), release view does not move same
from there drag to the last pane row, then 1 report on the footer row, held 1 s +1 line +18 lines (one per 50 ms)
300 more reports on the footer row (ESC[<32;60..62;45M) view jumps 300 lines to file1.py line 146 +1 line
held 3 s more no change stops at line 92, the end of the hunk

Change

  • A report for the cell already reported (the pressed cell first) does nothing. A pixel-by-pixel jiggle stays a click, and does not make a one-line selection with a toolbar.
  • Only a row of code takes the drag's click. A heading, a gap or the sticky heading takes no click, because a click there could open the gap or move the view.
  • No report scrolls. When the pointer goes past an edge, the drag clicks the code line at that edge once. While the pointer stays past the edge, the view scrolls one line per STEP (50 ms) from Screen::tick. It scrolls only while the cursor is in the anchor's hunk and the hunk has more lines in that direction. While a drag is held past an edge, the loop wakes every 50 ms.
  • New module review/mouse/edge.rs. Diff::hunk_span now also returns the hunk's index.

Document screen (second commit)

app/input.rs (v0.11.1, lines 617-621) scrolled one row for each drag report past the text's top or bottom: 100 reports on the last row scrolled 100 rows, in v0.11.0 too. It now follows the same rules (app/drag.rs):

  • A report for the cell already reported does nothing, and no report scrolls.
  • Held past an edge, the document scrolls one row per 50 ms on the loop's tick, as far as its end.
  • A key, a paste, a resize or a lost focus stops the timer. The next report starts it again.

The edge timer (Edge, STEP) is in ui::drag. Both screens use it.

Focus reports (ESC[I / ESC[O) during a drag scroll nothing, in v0.11.0, v0.11.1 and here.

Reports outside the terminal

Both screens ignore a mouse report for a cell outside the frame last drawn: pixel positions, rows past the terminal, u16::MAX. Before, such a report was read as the pointer past the bottom. A release there still ends the drag, at the nearest cell, so no drag stays held (ui::drag::on_screen).

Tests

New, in review/tests/drag_burst.rs (160x45, split diff):

  • a_burst_of_drag_reports_inside_the_pane_moves_no_view_and_selects_press_to_pointer
  • reports_in_one_burst_end_as_the_same_reports_one_per_frame (fails on main)
  • reports_for_the_pressed_cell_leave_a_click_a_click (fails on main)
  • a_press_on_any_row_of_the_pane_leaves_the_view_where_it_is
  • held_past_the_bottom_the_view_scrolls_a_line_per_step_however_many_reports
  • held_past_the_bottom_the_view_stops_at_the_end_of_the_drags_hunk
  • other_buttons_the_horizontal_wheel_and_focus_reports_during_a_drag_scroll_nothing
  • reports_outside_the_terminal_are_ignored_and_a_release_there_still_ends_the_drag

New, in app/drag_tests.rs (document screen, 120x40):

  • drag_reports_in_a_burst_scroll_nothing_and_end_as_the_same_reports_one_per_frame
  • held_past_the_bottom_the_document_scrolls_a_row_per_step_however_many_reports
  • held_past_the_bottom_the_document_stops_at_its_end
  • reports_outside_the_terminal_are_ignored_and_a_release_there_still_ends_the_drag

dragging_past_the_bottom_scrolls_and_keeps_selecting and an_upward_drag_that_scrolled_keeps_the_view_where_it_went_on_release now hold the drag on the timer, not with one report per step. They now drag over the footer row, not over rows past the terminal, which are now ignored.

Not verified

The fix was not run in a real Rex or Herdr window. The link to the report is inferred: the bug needs the pointer above or below the pane (the header row or the footer row), which a drag toward the last visible line easily reaches.

The document-screen change was checked by its tests only. The tmux runs above were made before it, and the release binary was not run again.

A drag past the diff pane's top or bottom moved the cursor a line for
every mouse report, with no limit on the rate and no stop at the hunk
the selection is kept in. Terminals in a window can report every pixel
the pointer moves, so a drag that touched the footer row scrolled
hundreds of lines in a moment, through the other files to the end of
the diff. Several reports also arrive between two frames, and each
click after a scroll was hit-tested against the stale frame, so a
burst ended on other lines than the same reports one per frame.

Now a report for the cell already reported does nothing, only a line
of code takes the drag's click, and no report scrolls. Held past an
edge, the view scrolls a line per 50 ms on the event loop's tick, and
only while the anchor's hunk has lines that way.
…sense mouse reports are ignored

The document screen scrolled one row for every drag report past the
text's top or bottom, so a terminal that reports each pixel raced the
document to its end. It now follows the review: a report for the cell
already reported does nothing, no report scrolls, and held past an
edge the document scrolls a row per 50 ms on the loop's tick until it
ends. The edge timer moves to ui::drag, shared by both screens.

Both screens now ignore a mouse report for a cell outside the terminal
(pixel positions, a broken encoding) instead of reading it as the
pointer past the bottom. A release there still ends a drag, at the
nearest cell.
@backnotprop
backnotprop added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit 2833a4e Nov 24, 2026
3 checks passed
@backnotprop
backnotprop deleted the fix/drag-scroll branch November 24, 2026 00:12
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