From a7284adafab23d96330584bb0db38c85b0f171e5 Mon Sep 17 00:00:00 2001 From: Smit Barmase Date: Fri, 18 Jul 2025 06:07:52 +0530 Subject: [PATCH] =?UTF-8?q?editor:=20Fix=20cursor=20doesn=E2=80=99t=20move?= =?UTF-8?q?=20up=20and=20down=20on=20arrow=20keys=20when=20no=20completion?= =?UTF-8?q?s=20are=20shown=20(#34678)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #34338 After https://github.com/zed-industries/zed/pull/31872, to avoid re-querying language servers, we keep the context menu around, which stores initial query, completions items, etc., even though it may not contain any items and hence not be rendered on screen. In this state, up/down arrows try to switch focus in the context menu instead of propagating it to the editor. Hence blocking buffer movement. This PR fixes it by changing the context for `menu`, `showing_completions`, and `showing_code_actions` to only be added when the menu is actually being rendered (i.e., not empty). Release Notes: - Fix an issue where the cursor doesn’t move up and down on arrow keys when no completions are shown. --- crates/editor/src/code_context_menus.rs | 2 +- crates/editor/src/editor.rs | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/crates/editor/src/code_context_menus.rs b/crates/editor/src/code_context_menus.rs index c7477837dd0b6cdf8e818f16491cda569ec7fc47..9f842836ed20bb960c1e112398b8939d6f77e6cc 100644 --- a/crates/editor/src/code_context_menus.rs +++ b/crates/editor/src/code_context_menus.rs @@ -1384,7 +1384,7 @@ impl CodeActionsMenu { } } - fn visible(&self) -> bool { + pub fn visible(&self) -> bool { !self.actions.is_empty() } diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 6ad4fc0318ac322c03d45d585891ca729ef06b83..c3187f6b51188c946ac07b3c40f2a235e554c623 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -2382,13 +2382,17 @@ impl Editor { } match self.context_menu.borrow().as_ref() { - Some(CodeContextMenu::Completions(_)) => { - key_context.add("menu"); - key_context.add("showing_completions"); + Some(CodeContextMenu::Completions(menu)) => { + if menu.visible() { + key_context.add("menu"); + key_context.add("showing_completions"); + } } - Some(CodeContextMenu::CodeActions(_)) => { - key_context.add("menu"); - key_context.add("showing_code_actions") + Some(CodeContextMenu::CodeActions(menu)) => { + if menu.visible() { + key_context.add("menu"); + key_context.add("showing_code_actions") + } } None => {} }