Skip to content

fix(review): keep the cursor line across a review layout toggle - #427

Merged
barrettruth merged 2 commits into
mainfrom
fix/review-toggle-cursor-line
Aug 12, 2026
Merged

fix(review): keep the cursor line across a review layout toggle#427
barrettruth merged 2 commits into
mainfrom
fix/review-toggle-cursor-line

Conversation

@barrettruth

Copy link
Copy Markdown
Owner

Problem

The review layout toggle carried a file, not a position. Going into the split, the selection handed over was the file plus its hunk index, so the pair opened at the first change of the hunk rather than the line that was selected. Coming back, goto_review_map_selection() looked the file up in the quickfix list and jumped to its entry, which is the diff --git header row, so gs out of a split always landed at the top of that file's diff no matter where the cursor had been.

The mapping needed for the return trip already existed in one direction: a split row resolves to a source line through the pane's alignment rows, which is how opening the source file from a split lands on the right line. Nothing computed the inverse.

Solution

Both directions now travel as a source position, a side and a line number, which is the one thing a review map row and a split row can both name. Entering resolves the map row to that position through the hunk model and moves the pane pair to the row that shows it; leaving reads the position under the split cursor and resolves it back to the map row that carries it, falling back to the file's quickfix row when the row names no source line, such as a file or hunk header. The split position is read when the toggle happens rather than when the split was opened, so moving around inside the split is reflected in the map.

Rows facing a filler, a deletion with nothing opposite it, take their position from the other pane, so deleted lines return to their own map row instead of the nearest surviving line. Duplicate paths across review sections resolve by review key, so a file that appears both staged and unstaged returns to the section it came from.

Base automatically changed from fix/generated-buffer-reload to main August 12, 2026 23:50
Toggling a review map into the split carried a file, not a position: the
selection handed to the split was the file plus its hunk index, and the way
back was a quickfix lookup that jumped to the file's entry. Leaving the split
therefore landed on the file header row in the map no matter where the cursor
had been, and entering it landed on the first change of a hunk rather than the
line that was selected.

Both directions now travel as a source position, a side and a line number,
which is the one thing a review map row and a split row can both name. Going in
resolves the map row to that position through the hunk model and moves the pane
pair to the row that shows it; coming back reads the position under the split
cursor and resolves it to the map row that carries it, falling back to the
file's quickfix row when the row names no source line. The split position is
read when the toggle happens rather than when the split opened, so moving
around inside the split is respected.

Rows that face a filler, a deletion with nothing opposite it, take the position
from the other pane, so deleted lines return to their own map row instead of
the nearest surviving line. Duplicate paths across review sections resolve by
review key, so a file that appears staged and unstaged returns to the section
it came from.
@barrettruth
barrettruth force-pushed the fix/review-toggle-cursor-line branch from 78f0bdf to fb6c1a7 Compare August 12, 2026 23:51
A removed line and the line that replaced it occupy one row in the split and
two in the map, so returning from the right pane lands on the added line even
when the removed line is what opened the split. This is the cursor following
the line it is actually on, and it settles there rather than drifting, but the
rule was left implicit.
@barrettruth
barrettruth merged commit 1bfda48 into main Aug 12, 2026
5 checks passed
@barrettruth
barrettruth deleted the fix/review-toggle-cursor-line branch August 12, 2026 23:56
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