From 48cdefe6cff2a688f755c6d995c2c487a87e1b8b Mon Sep 17 00:00:00 2001 From: Julia Date: Tue, 24 Oct 2023 11:17:42 +0200 Subject: [PATCH] Re-understand that the line just below git deletion is "inside" hunk Fixes "go to previous hunk" getting stuck on a deletion, never going further up --- crates/editor/src/editor.rs | 6 ++--- crates/editor/src/editor_tests.rs | 40 +++++++++++++++++++++++++++++++ crates/editor/src/git.rs | 6 ++--- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 82945fc00b..380cf1a5e6 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -7308,11 +7308,11 @@ 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| { + .filter(|hunk| { if is_wrapped { - false + true } else { - hunk.contains_display_row(display_point.row()) + !hunk.contains_display_row(display_point.row()) } }) .dedup(); diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index 6421fc6f7a..a847e33c1a 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -6800,6 +6800,46 @@ async fn go_to_hunk(deterministic: Arc, cx: &mut gpui::TestAppCon .unindent(), ); + cx.update_editor(|editor, cx| { + editor.go_to_prev_hunk(&GoToPrevHunk, cx); + }); + + cx.assert_editor_state( + &r#" + use some::modified; + + ˇ + fn main() { + println!("hello there"); + + println!("around the"); + println!("world"); + } + "# + .unindent(), + ); + + cx.update_editor(|editor, cx| { + for _ in 0..3 { + editor.go_to_prev_hunk(&GoToPrevHunk, cx); + } + }); + + cx.assert_editor_state( + &r#" + use some::modified; + + + fn main() { + ˇ println!("hello there"); + + println!("around the"); + println!("world"); + } + "# + .unindent(), + ); + cx.update_editor(|editor, cx| { editor.fold(&Fold, cx); diff --git a/crates/editor/src/git.rs b/crates/editor/src/git.rs index 3452138126..0ec7358df7 100644 --- a/crates/editor/src/git.rs +++ b/crates/editor/src/git.rs @@ -36,7 +36,7 @@ impl DisplayDiffHunk { DisplayDiffHunk::Unfolded { display_row_range, .. - } => display_row_range.start..=display_row_range.end - 1, + } => display_row_range.start..=display_row_range.end, }; range.contains(&display_row) @@ -77,8 +77,8 @@ pub fn diff_hunk_to_display(hunk: DiffHunk, snapshot: &DisplaySnapshot) -> } else { let start = hunk_start_point.to_display_point(snapshot).row(); - let hunk_end_row_inclusive = hunk.buffer_range.end.max(hunk.buffer_range.start); - let hunk_end_point = Point::new(hunk_end_row_inclusive, 0); + let hunk_end_row = hunk.buffer_range.end.max(hunk.buffer_range.start); + let hunk_end_point = Point::new(hunk_end_row, 0); let end = hunk_end_point.to_display_point(snapshot).row(); DisplayDiffHunk::Unfolded {