From b7a242b22ea42f39f04133e38a5226d53c258304 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Tue, 11 Mar 2025 18:29:22 -0400 Subject: [PATCH] Tweak stage/unstage-and-next to start a commit instead of wrapping in the project diff editor (cherry-pick #26434) (#26490) Cherry-picked Tweak stage/unstage-and-next to start a commit instead of wrapping in the project diff editor (#26434) Release Notes: - Git Beta: improved the stage-and-next and unstage-and-next actions in the project diff editor to start a commit after acting on the last hunk Co-authored-by: Cole Miller --- crates/editor/src/editor.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 1a124f31ae6eaeade8ed6abdc87bc3c15614b823..87928e30488d41e85bf919929f4436aa950df780 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -13680,7 +13680,37 @@ impl Editor { } self.stage_or_unstage_diff_hunks(stage, ranges, cx); - self.go_to_next_hunk(&GoToHunk, window, cx); + let snapshot = self.snapshot(window, cx); + let position = self.selections.newest::(cx).head(); + let mut row = snapshot + .buffer_snapshot + .diff_hunks_in_range(position..snapshot.buffer_snapshot.max_point()) + .find(|hunk| hunk.row_range.start.0 > position.row) + .map(|hunk| hunk.row_range.start); + + let all_diff_hunks_expanded = self.buffer().read(cx).all_diff_hunks_expanded(); + // Outside of the project diff editor, wrap around to the beginning. + if !all_diff_hunks_expanded { + row = row.or_else(|| { + snapshot + .buffer_snapshot + .diff_hunks_in_range(Point::zero()..position) + .find(|hunk| hunk.row_range.end.0 < position.row) + .map(|hunk| hunk.row_range.start) + }); + } + + if let Some(row) = row { + let destination = Point::new(row.0, 0); + let autoscroll = Autoscroll::center(); + + self.unfold_ranges(&[destination..destination], false, false, cx); + self.change_selections(Some(autoscroll), window, cx, |s| { + s.select_ranges([destination..destination]); + }); + } else if all_diff_hunks_expanded { + window.dispatch_action(::git::ExpandCommitEditor.boxed_clone(), cx); + } } fn do_stage_or_unstage(