Allow context menu to be cancelled after deploying it twice

Previously, two right clicks would cause an issue with cancelling the context menu via escape.
This commit is contained in:
Nathan Sobo 2022-05-27 12:00:11 -06:00
parent c3baf2748f
commit 9909fc529b
2 changed files with 7 additions and 1 deletions

View file

@ -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;

View file

@ -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);
}