From 06ab2ace7271af2d751f01f984ef8567b184a7e5 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 30 May 2022 18:36:36 +0200 Subject: [PATCH] Don't steal focus from context menu when dispatching an action --- crates/context_menu/src/context_menu.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/context_menu/src/context_menu.rs b/crates/context_menu/src/context_menu.rs index 33ccb35dbe..273bb588af 100644 --- a/crates/context_menu/src/context_menu.rs +++ b/crates/context_menu/src/context_menu.rs @@ -141,10 +141,12 @@ impl ContextMenu { fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext) { self.reset(cx); - if cx.handle().is_focused(cx) { - let window_id = cx.window_id(); - (**cx).focus(window_id, self.previously_focused_view_id.take()); - } + cx.defer(|this, cx| { + if cx.handle().is_focused(cx) { + let window_id = cx.window_id(); + (**cx).focus(window_id, this.previously_focused_view_id.take()); + } + }); } fn reset(&mut self, cx: &mut ViewContext) {