From edadc6f9383ca1aa794f5e7bbd817fb0e3c3e083 Mon Sep 17 00:00:00 2001 From: Gus Date: Tue, 14 May 2024 16:18:21 -0700 Subject: [PATCH] Fix bug with keymaps flickering in mouse menu (#11795) Fixes a bug where Vim bindings would flash in the mouse context menu and then be replaced by the default keybindings. Also fixes those bindings not being usable while the mouse context menu was open. Release Notes: - Fixed bug where Vim bindings were not available when mouse context menu was open --------- Co-authored-by: Conrad Irwin --- crates/editor/src/editor.rs | 6 ++++++ crates/editor/src/mouse_context_menu.rs | 10 ++++++++-- crates/vim/src/vim.rs | 7 +++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index bcb09e12cdf1381d3f72e0399320c538d6bd2173..12aeb7baa019f8df5d7f12a183fb532404c132ec 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -1721,6 +1721,12 @@ impl Editor { this } + pub fn mouse_menu_is_focused(&self, cx: &mut WindowContext) -> bool { + self.mouse_context_menu + .as_ref() + .is_some_and(|menu| menu.context_menu.focus_handle(cx).is_focused(cx)) + } + fn key_context(&self, cx: &AppContext) -> KeyContext { let mut key_context = KeyContext::new_with_defaults(); key_context.add("Editor"); diff --git a/crates/editor/src/mouse_context_menu.rs b/crates/editor/src/mouse_context_menu.rs index c3a6be3394e0f18eaaefa6c3896f5452fa13b0d1..4f5abc4cec1e4372b62430c459cb173123b4820f 100644 --- a/crates/editor/src/mouse_context_menu.rs +++ b/crates/editor/src/mouse_context_menu.rs @@ -70,8 +70,10 @@ pub fn deploy_context_menu( s.set_pending_display_range(point..point, SelectMode::Character); }); + let focus = cx.focused(); ui::ContextMenu::build(cx, |menu, _cx| { - menu.action("Rename Symbol", Box::new(Rename)) + let builder = menu + .action("Rename Symbol", Box::new(Rename)) .action("Go to Definition", Box::new(GoToDefinition)) .action("Go to Type Definition", Box::new(GoToTypeDefinition)) .action("Go to Implementation", Box::new(GoToImplementation)) @@ -84,7 +86,11 @@ pub fn deploy_context_menu( ) .separator() .action("Reveal in Finder", Box::new(RevealInFinder)) - .action("Open in Terminal", Box::new(OpenInTerminal)) + .action("Open in Terminal", Box::new(OpenInTerminal)); + match focus { + Some(focus) => builder.context(focus), + None => builder, + } }) }; let mouse_context_menu = MouseContextMenu::new(position, context_menu, cx); diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index b8cfafc04d4ecee163145941e2c7716c9060fc00..52aa84e6862d12bde0ef042dd0ed5f1de4f625e1 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -813,12 +813,11 @@ impl Vim { editor.set_input_enabled(!state.vim_controlled()); editor.set_autoindent(state.should_autoindent()); editor.selections.line_mode = matches!(state.mode, Mode::VisualLine); - if editor.is_focused(cx) { + if editor.is_focused(cx) || editor.mouse_menu_is_focused(cx) { editor.set_keymap_context_layer::(state.keymap_context_layer(), cx); - // disables vim if the rename editor is focused, - // but not if the command palette is open. + // disable vim mode if a sub-editor (inline assist, rename, etc.) is focused } else if editor.focus_handle(cx).contains_focused(cx) { - editor.remove_keymap_context_layer::(cx) + editor.remove_keymap_context_layer::(cx); } }); }