From 6fb1081b615274a4d2850ec8a9b820a51e94d91d Mon Sep 17 00:00:00 2001 From: Alvaro Parker <64918109+AlvaroParker@users.noreply.github.com> Date: Sat, 21 Jun 2025 17:43:00 -0400 Subject: [PATCH] Disable next/previous hunk menu items when there are no hunks (#32907) Closes #32887 Release Notes: - Button menu hunk is disabled if there are no changes --- crates/zed/src/zed/quick_action_bar.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/zed/src/zed/quick_action_bar.rs b/crates/zed/src/zed/quick_action_bar.rs index 7bfab92e9ad29c1a8c5f020d58606fec08467e94..52c4ff3831e4b8ede0d4aea5fe2b22ec9fda3f81 100644 --- a/crates/zed/src/zed/quick_action_bar.rs +++ b/crates/zed/src/zed/quick_action_bar.rs @@ -217,6 +217,12 @@ impl Render for QuickActionBar { }); let editor_selections_dropdown = selection_menu_enabled.then(|| { + let has_diff_hunks = editor + .read(cx) + .buffer() + .read(cx) + .snapshot(cx) + .has_diff_hunks(); let focus = editor.focus_handle(cx); PopoverMenu::new("editor-selections-dropdown") @@ -251,8 +257,18 @@ impl Render for QuickActionBar { .action("Next Problem", Box::new(GoToDiagnostic)) .action("Previous Problem", Box::new(GoToPreviousDiagnostic)) .separator() - .action("Next Hunk", Box::new(GoToHunk)) - .action("Previous Hunk", Box::new(GoToPreviousHunk)) + .map(|menu| { + if has_diff_hunks { + menu.action("Next Hunk", Box::new(GoToHunk)) + .action("Previous Hunk", Box::new(GoToPreviousHunk)) + } else { + menu.disabled_action("Next Hunk", Box::new(GoToHunk)) + .disabled_action( + "Previous Hunk", + Box::new(GoToPreviousHunk), + ) + } + }) .separator() .action("Move Line Up", Box::new(MoveLineUp)) .action("Move Line Down", Box::new(MoveLineDown))