Skip to content

Commit a76cd77

Browse files
authored
Disable hunk diff arrow buttons when there's only one hunk (#21437)
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
1 parent a8c7e61 commit a76cd77

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

crates/editor/src/hunk_diff.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,12 @@ impl Editor {
399399
}
400400
}
401401

402+
fn has_multiple_hunks(&self, cx: &AppContext) -> bool {
403+
let snapshot = self.buffer.read(cx).snapshot(cx);
404+
let mut hunks = snapshot.git_diff_hunks_in_range(MultiBufferRow::MIN..MultiBufferRow::MAX);
405+
hunks.nth(1).is_some()
406+
}
407+
402408
fn hunk_header_block(
403409
&self,
404410
hunk: &HoveredHunk,
@@ -428,6 +434,7 @@ impl Editor {
428434
render: Arc::new({
429435
let editor = cx.view().clone();
430436
let hunk = hunk.clone();
437+
let has_multiple_hunks = self.has_multiple_hunks(cx);
431438

432439
move |cx| {
433440
let hunk_controls_menu_handle =
@@ -471,6 +478,7 @@ impl Editor {
471478
IconButton::new("next-hunk", IconName::ArrowDown)
472479
.shape(IconButtonShape::Square)
473480
.icon_size(IconSize::Small)
481+
.disabled(!has_multiple_hunks)
474482
.tooltip({
475483
let focus_handle = editor.focus_handle(cx);
476484
move |cx| {
@@ -499,6 +507,7 @@ impl Editor {
499507
IconButton::new("prev-hunk", IconName::ArrowUp)
500508
.shape(IconButtonShape::Square)
501509
.icon_size(IconSize::Small)
510+
.disabled(!has_multiple_hunks)
502511
.tooltip({
503512
let focus_handle = editor.focus_handle(cx);
504513
move |cx| {

0 commit comments

Comments
 (0)