diff --git a/crates/context_menu/src/context_menu.rs b/crates/context_menu/src/context_menu.rs index 507a88c5f2..dc3eee2ed8 100644 --- a/crates/context_menu/src/context_menu.rs +++ b/crates/context_menu/src/context_menu.rs @@ -169,7 +169,9 @@ impl ContextMenu { self.items = items.collect(); self.position = position; self.visible = true; - self.previously_focused_view_id = cx.focused_view_id(cx.window_id()); + if !cx.is_self_focused() { + self.previously_focused_view_id = cx.focused_view_id(cx.window_id()); + } cx.focus_self(); } else { self.visible = false; diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 3575accbeb..788dadec49 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -3255,6 +3255,10 @@ impl<'a, T: View> ViewContext<'a, T> { self.app.focus(self.window_id, Some(self.view_id)); } + pub fn is_self_focused(&self) -> bool { + self.app.focused_view_id(self.window_id) == Some(self.view_id) + } + pub fn blur(&mut self) { self.app.focus(self.window_id, None); }