Fix diff_hunk_before in a multibuffer (#26059)

Also simplify it to avoid doing a bunch of unnecessary work.

Co-Authored-By: Cole <cole@zed.dev>

Closes #ISSUE

Release Notes:

- git: Fix jumping to the previous diff hunk

---------

Co-authored-by: Cole <cole@zed.dev>
This commit is contained in:
Conrad Irwin 2025-03-04 20:07:19 -07:00 committed by GitHub
parent 3e64f38ba0
commit d7b90f4204
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 162 additions and 138 deletions

View file

@ -11544,15 +11544,16 @@ impl Editor {
direction: Direction,
window: &mut Window,
cx: &mut Context<Editor>,
) -> Option<MultiBufferDiffHunk> {
let hunk = if direction == Direction::Next {
) {
let row = if direction == Direction::Next {
self.hunk_after_position(snapshot, position)
.map(|hunk| hunk.row_range.start)
} else {
self.hunk_before_position(snapshot, position)
};
if let Some(hunk) = &hunk {
let destination = Point::new(hunk.row_range.start.0, 0);
if let Some(row) = row {
let destination = Point::new(row.0, 0);
let autoscroll = Autoscroll::center();
self.unfold_ranges(&[destination..destination], false, false, cx);
@ -11560,8 +11561,6 @@ impl Editor {
s.select_ranges([destination..destination]);
});
}
hunk
}
fn hunk_after_position(
@ -11602,7 +11601,7 @@ impl Editor {
&mut self,
snapshot: &EditorSnapshot,
position: Point,
) -> Option<MultiBufferDiffHunk> {
) -> Option<MultiBufferRow> {
snapshot
.buffer_snapshot
.diff_hunk_before(position)