Floyd Wang 2025-12-05 17:09:37 +08:00 committed by GitHub
parent 893155bcee
commit bc1092a6e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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(),