Merge pull request #2458 from zed-industries/fix-context-menu-click
Always dismiss context menu on click
This commit is contained in:
parent
36590cf22d
commit
fa6e8c9bfc
1 changed files with 9 additions and 16 deletions
|
@ -126,7 +126,6 @@ pub struct ContextMenu {
|
||||||
selected_index: Option<usize>,
|
selected_index: Option<usize>,
|
||||||
visible: bool,
|
visible: bool,
|
||||||
previously_focused_view_id: Option<usize>,
|
previously_focused_view_id: Option<usize>,
|
||||||
clicked: bool,
|
|
||||||
parent_view_id: usize,
|
parent_view_id: usize,
|
||||||
_actions_observation: Subscription,
|
_actions_observation: Subscription,
|
||||||
}
|
}
|
||||||
|
@ -189,7 +188,6 @@ impl ContextMenu {
|
||||||
selected_index: Default::default(),
|
selected_index: Default::default(),
|
||||||
visible: Default::default(),
|
visible: Default::default(),
|
||||||
previously_focused_view_id: Default::default(),
|
previously_focused_view_id: Default::default(),
|
||||||
clicked: false,
|
|
||||||
parent_view_id,
|
parent_view_id,
|
||||||
_actions_observation: cx.observe_actions(Self::action_dispatched),
|
_actions_observation: cx.observe_actions(Self::action_dispatched),
|
||||||
}
|
}
|
||||||
|
@ -205,18 +203,14 @@ impl ContextMenu {
|
||||||
.iter()
|
.iter()
|
||||||
.position(|item| item.action_id() == Some(action_id))
|
.position(|item| item.action_id() == Some(action_id))
|
||||||
{
|
{
|
||||||
if self.clicked {
|
self.selected_index = Some(ix);
|
||||||
self.cancel(&Default::default(), cx);
|
cx.notify();
|
||||||
} else {
|
cx.spawn(|this, mut cx| async move {
|
||||||
self.selected_index = Some(ix);
|
cx.background().timer(Duration::from_millis(50)).await;
|
||||||
cx.notify();
|
this.update(&mut cx, |this, cx| this.cancel(&Default::default(), cx))?;
|
||||||
cx.spawn(|this, mut cx| async move {
|
anyhow::Ok(())
|
||||||
cx.background().timer(Duration::from_millis(50)).await;
|
})
|
||||||
this.update(&mut cx, |this, cx| this.cancel(&Default::default(), cx))?;
|
.detach_and_log_err(cx);
|
||||||
anyhow::Ok(())
|
|
||||||
})
|
|
||||||
.detach_and_log_err(cx);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +250,6 @@ impl ContextMenu {
|
||||||
self.items.clear();
|
self.items.clear();
|
||||||
self.visible = false;
|
self.visible = false;
|
||||||
self.selected_index.take();
|
self.selected_index.take();
|
||||||
self.clicked = false;
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,7 +449,7 @@ impl ContextMenu {
|
||||||
.on_up(MouseButton::Left, |_, _, _| {}) // Capture these events
|
.on_up(MouseButton::Left, |_, _, _| {}) // Capture these events
|
||||||
.on_down(MouseButton::Left, |_, _, _| {}) // Capture these events
|
.on_down(MouseButton::Left, |_, _, _| {}) // Capture these events
|
||||||
.on_click(MouseButton::Left, move |_, menu, cx| {
|
.on_click(MouseButton::Left, move |_, menu, cx| {
|
||||||
menu.clicked = true;
|
menu.cancel(&Default::default(), cx);
|
||||||
let window_id = cx.window_id();
|
let window_id = cx.window_id();
|
||||||
match &action {
|
match &action {
|
||||||
ContextMenuItemAction::Action(action) => {
|
ContextMenuItemAction::Action(action) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue