Diff View: Scroll to center of hunks when reviewing (#25846)

When reviewing hunks, scroll to put them at the center of the screen
so you can better see the context around that hunk.

The field `center_cursor` was added to the actions `editor::GoToHunk`
and `editor::GoToPrevHunk`, this was set to `false` by default in
keymaps, as it wouldn't help with in-editor navigation.

The field is set to `true` for when you trigger `git::StageAndNext`
and `git::UnstageAndNext`, this is also `true` for the buttons in the
Diff View toolbar.

Release Notes:

- N/A
This commit is contained in:
João Marcos 2025-03-01 00:20:26 -03:00 committed by GitHub
parent a2876f5d3e
commit 2d61a51ded
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 140 additions and 66 deletions

View file

@ -8873,7 +8873,7 @@ fn diff_hunk_controls(
move |window, cx| {
Tooltip::for_action_in(
"Next Hunk",
&GoToHunk,
&GoToHunk::default(),
&focus_handle,
window,
cx,
@ -8887,8 +8887,9 @@ fn diff_hunk_controls(
let snapshot = editor.snapshot(window, cx);
let position =
hunk_range.end.to_point(&snapshot.buffer_snapshot);
editor
.go_to_hunk_after_position(&snapshot, position, window, cx);
editor.go_to_hunk_after_or_before_position(
&snapshot, position, true, true, window, cx,
);
editor.expand_selected_diff_hunks(cx);
});
}
@ -8904,7 +8905,7 @@ fn diff_hunk_controls(
move |window, cx| {
Tooltip::for_action_in(
"Previous Hunk",
&GoToPrevHunk,
&GoToPrevHunk::default(),
&focus_handle,
window,
cx,
@ -8918,7 +8919,9 @@ fn diff_hunk_controls(
let snapshot = editor.snapshot(window, cx);
let point =
hunk_range.start.to_point(&snapshot.buffer_snapshot);
editor.go_to_hunk_before_position(&snapshot, point, window, cx);
editor.go_to_hunk_after_or_before_position(
&snapshot, point, false, true, window, cx,
);
editor.expand_selected_diff_hunks(cx);
});
}