From bf9b2a3ace1db0b60746fc35d1d7c04fc141815a Mon Sep 17 00:00:00 2001 From: Peter Tripp Date: Wed, 25 Jun 2025 12:48:15 -0400 Subject: [PATCH] Fix empty code actions menu trapping cursor (#33386) Closes: https://github.com/zed-industries/zed/issues/33382 Follow-up to: https://github.com/zed-industries/zed/pull/32579 CC: @ConradIrwin @Anthony-Eid Release Notes: - Fixed an issue with empty code actions menu locking the cursor (Preview Only) --- crates/editor/src/code_context_menus.rs | 2 +- crates/editor/src/editor.rs | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/crates/editor/src/code_context_menus.rs b/crates/editor/src/code_context_menus.rs index 85b8aa005ed1ed14a20f1e867230bfe8a58d6521..ea02b7d8a0bc3843fb03d39df5ac7cd8080f0da8 100644 --- a/crates/editor/src/code_context_menus.rs +++ b/crates/editor/src/code_context_menus.rs @@ -1205,7 +1205,7 @@ impl CodeActionContents { tasks_len + code_actions_len + self.debug_scenarios.len() } - fn is_empty(&self) -> bool { + pub fn is_empty(&self) -> bool { self.len() == 0 } diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index c58ab6589b25243e78ad1fb38a04b2051454bbb8..18cc9b2b7f7a0491a5ba2bd0e7b0a768eee2c41c 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -5941,15 +5941,23 @@ impl Editor { editor.update_in(cx, |editor, window, cx| { crate::hover_popover::hide_hover(editor, cx); + let actions = CodeActionContents::new( + resolved_tasks, + code_actions, + debug_scenarios, + task_context.unwrap_or_default(), + ); + + // Don't show the menu if there are no actions available + if actions.is_empty() { + cx.notify(); + return Task::ready(Ok(())); + } + *editor.context_menu.borrow_mut() = Some(CodeContextMenu::CodeActions(CodeActionsMenu { buffer, - actions: CodeActionContents::new( - resolved_tasks, - code_actions, - debug_scenarios, - task_context.unwrap_or_default(), - ), + actions, selected_item: Default::default(), scroll_handle: UniformListScrollHandle::default(), deployed_from,