Avoid retrieving layout bounds inside of right click menu event handler

Co-Authored-By: Nathan <nathan@zed.dev>
Co-Authored-By: Max <max@zed.dev>
This commit is contained in:
Antonio Scandurra 2024-01-15 19:27:18 +01:00
parent 90f4c70a82
commit a56265e607

View File

@ -134,6 +134,7 @@ impl<M: ManagedView> Element for RightClickMenu<M> {
let position = element_state.position.clone();
let attach = self.attach.clone();
let child_layout_id = element_state.child_layout_id.clone();
let child_bounds = cx.layout_bounds(child_layout_id.unwrap());
cx.on_mouse_event(move |event: &MouseDownEvent, phase, cx| {
if phase == DispatchPhase::Bubble
@ -161,9 +162,7 @@ impl<M: ManagedView> Element for RightClickMenu<M> {
*menu.borrow_mut() = Some(new_menu);
*position.borrow_mut() = if attach.is_some() && child_layout_id.is_some() {
attach
.unwrap()
.corner(cx.layout_bounds(child_layout_id.unwrap()))
attach.unwrap().corner(child_bounds)
} else {
cx.mouse_position()
};