context_menu: Prevent mouse events when menu popped out (#1750)
## Before https://github.com/user-attachments/assets/6cb5a767-d888-43f1-b5cc-1f3c5748389d ## After https://github.com/user-attachments/assets/0846d0e2-2311-47d1-8d5b-2e7bbc347fe3
This commit is contained in:
parent
893155bcee
commit
bc1092a6e1
1 changed files with 26 additions and 15 deletions
|
|
@ -1,10 +1,10 @@
|
||||||
use std::{cell::RefCell, rc::Rc};
|
use std::{cell::RefCell, rc::Rc};
|
||||||
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
anchored, deferred, div, prelude::FluentBuilder, px, AnyElement, App, Context, Corner,
|
AnyElement, App, Context, Corner, DismissEvent, Element, ElementId, Entity, Focusable,
|
||||||
DismissEvent, Element, ElementId, Entity, Focusable, GlobalElementId, InspectorElementId,
|
GlobalElementId, InspectorElementId, InteractiveElement, IntoElement, MouseButton,
|
||||||
InteractiveElement, IntoElement, MouseButton, MouseDownEvent, ParentElement, Pixels, Point,
|
MouseDownEvent, ParentElement, Pixels, Point, StyleRefinement, Styled, Subscription, Window,
|
||||||
StyleRefinement, Styled, Subscription, Window,
|
anchored, deferred, div, prelude::FluentBuilder, px,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::menu::PopupMenu;
|
use crate::menu::PopupMenu;
|
||||||
|
|
@ -168,18 +168,29 @@ impl<E: ParentElement + Styled + IntoElement + 'static> Element for ContextMenu<
|
||||||
if has_menu_item {
|
if has_menu_item {
|
||||||
menu_element = Some(
|
menu_element = Some(
|
||||||
deferred(
|
deferred(
|
||||||
anchored()
|
anchored().child(
|
||||||
.position(position)
|
div()
|
||||||
.snap_to_window_with_margin(px(8.))
|
.w(window.bounds().size.width)
|
||||||
.anchor(anchor)
|
.h(window.bounds().size.height)
|
||||||
.when_some(menu_view, |this, menu| {
|
.occlude()
|
||||||
// Focus the menu, so that can be handle the action.
|
.child(
|
||||||
if !menu.focus_handle(cx).contains_focused(window, cx) {
|
anchored()
|
||||||
menu.focus_handle(cx).focus(window);
|
.position(position)
|
||||||
}
|
.snap_to_window_with_margin(px(8.))
|
||||||
|
.anchor(anchor)
|
||||||
|
.when_some(menu_view, |this, menu| {
|
||||||
|
// Focus the menu, so that can be handle the action.
|
||||||
|
if !menu
|
||||||
|
.focus_handle(cx)
|
||||||
|
.contains_focused(window, cx)
|
||||||
|
{
|
||||||
|
menu.focus_handle(cx).focus(window);
|
||||||
|
}
|
||||||
|
|
||||||
this.child(div().occlude().child(menu.clone()))
|
this.child(menu.clone())
|
||||||
}),
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.with_priority(1)
|
.with_priority(1)
|
||||||
.into_any(),
|
.into_any(),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue