Don't steal focus from context menu when dispatching an action

This commit is contained in:
Antonio Scandurra 2022-05-30 18:36:36 +02:00
parent f832c0074f
commit 06ab2ace72

View file

@ -141,10 +141,12 @@ impl ContextMenu {
fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) { fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) {
self.reset(cx); self.reset(cx);
if cx.handle().is_focused(cx) { cx.defer(|this, cx| {
let window_id = cx.window_id(); if cx.handle().is_focused(cx) {
(**cx).focus(window_id, self.previously_focused_view_id.take()); let window_id = cx.window_id();
} (**cx).focus(window_id, this.previously_focused_view_id.take());
}
});
} }
fn reset(&mut self, cx: &mut ViewContext<Self>) { fn reset(&mut self, cx: &mut ViewContext<Self>) {