Skip to content

Commit

Permalink
Disable hunk diff arrow buttons when there's only one hunk (#21437)
Browse files Browse the repository at this point in the history
Closes #20817

| One hunk | Multiple hunks |
|--------|--------|
| <img width="800" alt="Screenshot 2024-12-03 at 09 42 49"
src="https://github.com/user-attachments/assets/7c2ff80a-d4d9-4a74-84b8-891fadfd4e6c">
| <img width="800" alt="Screenshot 2024-12-02 at 23 36 38"
src="https://github.com/user-attachments/assets/60ea94b8-0b23-43a2-afad-b816b4645d1f">
|

Release Notes:

- Fixed showing prev/next hunk navigation buttons when there is only one
hunk
  • Loading branch information
danilo-leal authored Dec 3, 2024
1 parent a8c7e61 commit a76cd77
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions crates/editor/src/hunk_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,12 @@ impl Editor {
}
}

fn has_multiple_hunks(&self, cx: &AppContext) -> bool {
let snapshot = self.buffer.read(cx).snapshot(cx);
let mut hunks = snapshot.git_diff_hunks_in_range(MultiBufferRow::MIN..MultiBufferRow::MAX);
hunks.nth(1).is_some()
}

fn hunk_header_block(
&self,
hunk: &HoveredHunk,
Expand Down Expand Up @@ -428,6 +434,7 @@ impl Editor {
render: Arc::new({
let editor = cx.view().clone();
let hunk = hunk.clone();
let has_multiple_hunks = self.has_multiple_hunks(cx);

move |cx| {
let hunk_controls_menu_handle =
Expand Down Expand Up @@ -471,6 +478,7 @@ impl Editor {
IconButton::new("next-hunk", IconName::ArrowDown)
.shape(IconButtonShape::Square)
.icon_size(IconSize::Small)
.disabled(!has_multiple_hunks)
.tooltip({
let focus_handle = editor.focus_handle(cx);
move |cx| {
Expand Down Expand Up @@ -499,6 +507,7 @@ impl Editor {
IconButton::new("prev-hunk", IconName::ArrowUp)
.shape(IconButtonShape::Square)
.icon_size(IconSize::Small)
.disabled(!has_multiple_hunks)
.tooltip({
let focus_handle = editor.focus_handle(cx);
move |cx| {
Expand Down

0 comments on commit a76cd77

Please sign in to comment.