Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Disable next/previous hunk menu items when there are no hunks (#32907)

Alvaro Parker6fb1081b6152
diff --git a/crates/zed/src/zed/quick_action_bar.rs b/crates/zed/src/zed/quick_action_bar.rs
index 7bfab92e9ad..52c4ff3831e 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))