From c147b5855866265ed22718202fa36226b1dfe220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marcos?= Date: Mon, 10 Mar 2025 11:23:17 -0300 Subject: [PATCH] Remove redundant checks in `do_stage_or_unstage_and_next` (#26364) Release Notes: - N/A --- crates/editor/src/editor.rs | 21 +++------------------ crates/editor/src/element.rs | 4 ++-- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 0ce23d77ddfc78c34f4faef62e2a646cca854a51..0664a6ea84f12cdc938317f090247292893047d0 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -11639,7 +11639,7 @@ impl Editor { fn go_to_next_hunk(&mut self, _: &GoToHunk, window: &mut Window, cx: &mut Context) { let snapshot = self.snapshot(window, cx); let selection = self.selections.newest::(cx); - self.go_to_hunk_after_or_before_position( + self.go_to_hunk_before_or_after_position( &snapshot, selection.head(), Direction::Next, @@ -11648,7 +11648,7 @@ impl Editor { ); } - fn go_to_hunk_after_or_before_position( + fn go_to_hunk_before_or_after_position( &mut self, snapshot: &EditorSnapshot, position: Point, @@ -11699,7 +11699,7 @@ impl Editor { ) { let snapshot = self.snapshot(window, cx); let selection = self.selections.newest::(cx); - self.go_to_hunk_after_or_before_position( + self.go_to_hunk_before_or_after_position( &snapshot, selection.head(), Direction::Prev, @@ -13861,21 +13861,6 @@ impl Editor { return; } - let snapshot = self.snapshot(window, cx); - let newest_range = self.selections.newest::(cx).range(); - - let run_twice = snapshot - .hunks_for_ranges([newest_range]) - .first() - .is_some_and(|hunk| { - let next_line = Point::new(hunk.row_range.end.0 + 1, 0); - self.hunk_after_position(&snapshot, next_line) - .is_some_and(|other| other.row_range == hunk.row_range) - }); - - if run_twice { - self.go_to_next_hunk(&GoToHunk, window, cx); - } self.stage_or_unstage_diff_hunks(stage, ranges, cx); self.go_to_next_hunk(&GoToHunk, window, cx); } diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index a094516d283173b46a54446b80256cc6db74966d..37fc451a6a7145757f45edb7c1294600d976c37f 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -9014,7 +9014,7 @@ 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_or_before_position( + editor.go_to_hunk_before_or_after_position( &snapshot, position, Direction::Next, @@ -9050,7 +9050,7 @@ fn diff_hunk_controls( let snapshot = editor.snapshot(window, cx); let point = hunk_range.start.to_point(&snapshot.buffer_snapshot); - editor.go_to_hunk_after_or_before_position( + editor.go_to_hunk_before_or_after_position( &snapshot, point, Direction::Prev,