Add test for go-to hunk and fix discovered bugs

This commit is contained in:
Julia 2022-10-28 15:07:53 -04:00
parent ae2021e073
commit 8361b4d47a
8 changed files with 145 additions and 72 deletions

View file

@ -5258,6 +5258,7 @@ impl Editor {
this: &mut Editor,
snapshot: &DisplaySnapshot,
initial_point: Point,
is_wrapped: bool,
direction: Direction,
cx: &mut ViewContext<Editor>,
) -> bool {
@ -5274,12 +5275,18 @@ impl Editor {
let display_point = initial_point.to_display_point(snapshot);
let mut hunks = hunks
.map(|hunk| diff_hunk_to_display(hunk, &snapshot))
.skip_while(|hunk| hunk.display_row_range().contains(&display_point.row()))
.skip_while(|hunk| {
if is_wrapped {
false
} else {
hunk.contains_display_row(display_point.row())
}
})
.dedup();
if let Some(hunk) = hunks.next() {
this.change_selections(Some(Autoscroll::Center), cx, |s| {
let row = hunk.display_row_range().start;
let row = hunk.start_display_row();
let point = DisplayPoint::new(row, 0);
s.select_display_ranges([point..point]);
});
@ -5290,12 +5297,12 @@ impl Editor {
}
}
if !seek_in_direction(self, &snapshot, selection.head(), direction, cx) {
if !seek_in_direction(self, &snapshot, selection.head(), false, direction, cx) {
let wrapped_point = match direction {
Direction::Next => Point::zero(),
Direction::Prev => snapshot.buffer_snapshot.max_point(),
};
seek_in_direction(self, &snapshot, wrapped_point, direction, cx);
seek_in_direction(self, &snapshot, wrapped_point, true, direction, cx);
}
}