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) {