Skip to content

fix(review): saving a note keeps the diff where it was - #201

Merged
backnotprop merged 2 commits into
mainfrom
fix/save-keeps-diff
Nov 24, 2026
Merged

backnotprop merged 2 commits into
mainfrom
fix/save-keeps-diff

Conversation

@backnotprop

Copy link
Copy Markdown
Contributor

Problem

In a wide split diff with long lines (for example the middle line at 30:70, wrap off, file list open, notes panel closed), saving the first comment on a mouse selection opened the notes panel. The diff got narrower, and every line was scrolled sideways: line numbers stayed, but only the tails of the longest lines were left. The review has no way to scroll back.

Cause

diffs-rs remembers the column a click lands on. When the pane next changes width it reflows and, if that column is no longer in view, makes it the first column shown (render::anchored_position, called from App::reflow_from).

Diff::select_in_place makes a mouse selection by clicking both ends at area.right() - 2, the new side's right edge. After the release the remembered column was about 100 cells into the line. The notes panel then took about 37 columns, the new side became narrower than that column, and the viewer scrolled to it.

A plain click far right in the code, followed by z, f, a resize or (/), did the same.

Fix

  • select_in_place clicks left of the code, on the side's first column.
  • After every left click the app forwards to the viewer, Diff::forget_column clicks the same row again on that column, if the cursor is on code there (wrap off). The cursor, the side and the selection do not change. The viewer's remembered column is then the one already shown first, so a later width change keeps each line's code where it was.
  • In the code review a saved note no longer opens the notes panel. when-notes is decided once, when the review opens: with notes the panel shows, without notes it stays away until z or Tab. The saved note still gets its gutter mark, the footer says note saved and notes hidden: z shows them, and the header's Send counts it. If the panel is already open, it stays open and shows the note. The document review is unchanged. The README says this now.

Tests

  • review::tests::save_keeps_view (new): a 190x50 terminal, split 30:70, wrap off, long lines, list open, panel closed, three wheel notches.

    • A drag up and a drag down over new lines 100-103, then c, type, Enter. The rows and each line's code column are the same before the box opened and after the save, and the panel stays closed.
    • The same for split 30, 50 and 70 and unified, with wrap on and off, and with the panel closed and opened by hand. Each one covers an old-side drag, a keyboard v selection, a suggestion and a cancelled box.
    • After a far-right click, with and without a selection: z open and close, f close and open, a resize, and (/).

    All three tests fail on main and pass here.

  • Tests that relied on the panel opening by itself now open it with z.

Engine note

The workaround is in this app. In diffs-rs, anchored_position (src/render.rs) turns a remembered click column into the horizontal offset when a reflow narrows the pane. A host that offers no horizontal scrolling would need either a way to keep the offset or one to clear the remembered column.

Saving the first comment opened the notes panel, the diff got narrower,
and diffs-rs scrolled every line sideways to the column the mouse
selection had last clicked. That click was at the new side's right edge,
so a wide split left only the tails of long lines, and nothing in the
review scrolls back.

- Selection clicks land left of the code, and after any click in the
  diff the row is clicked again there, so the viewer never holds on to a
  code column. Opening or closing the notes or the file list, resizing,
  moving the line between the sides or changing the layout keeps each
  line's code where it was.
- In the code review a saved note no longer opens the notes panel:
  `when-notes` is decided when the review opens. The note still gets its
  gutter mark, the footer says "note saved" and "notes hidden: z shows
  them", and the header's Send counts it.
@backnotprop
backnotprop added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit c831540 Nov 24, 2026
3 checks passed
@backnotprop
backnotprop deleted the fix/save-keeps-diff branch November 24, 2026 15:22
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