editor: Hide mouse context menu when modal is opened (#29127)
Closes #28787 The context menu appears before the modal because it is a Deferred element, which is always displayed above normal elements. Release Notes: Previously, the editor context menu appeared before the Command Palette. This commit ensures the editor context menu is hidden when a modal, including the Command Palette, is opened.
This commit is contained in:
parent
9a3434efb4
commit
6d2bdc3bac
4 changed files with 84 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
|||
use gpui::{
|
||||
AnyView, DismissEvent, Entity, FocusHandle, Focusable as _, ManagedView, MouseButton,
|
||||
Subscription,
|
||||
AnyView, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable as _, ManagedView,
|
||||
MouseButton, Subscription,
|
||||
};
|
||||
use ui::prelude::*;
|
||||
|
||||
|
@ -56,6 +56,10 @@ pub struct ModalLayer {
|
|||
dismiss_on_focus_lost: bool,
|
||||
}
|
||||
|
||||
pub(crate) struct ModalOpenedEvent;
|
||||
|
||||
impl EventEmitter<ModalOpenedEvent> for ModalLayer {}
|
||||
|
||||
impl Default for ModalLayer {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
|
@ -84,6 +88,7 @@ impl ModalLayer {
|
|||
}
|
||||
let new_modal = cx.new(|cx| build_view(window, cx));
|
||||
self.show_modal(new_modal, window, cx);
|
||||
cx.emit(ModalOpenedEvent);
|
||||
}
|
||||
|
||||
fn show_modal<V>(&mut self, new_modal: Entity<V>, window: &mut Window, cx: &mut Context<Self>)
|
||||
|
|
|
@ -781,6 +781,7 @@ pub enum Event {
|
|||
language: &'static str,
|
||||
},
|
||||
ZoomChanged,
|
||||
ModalOpened,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -1051,6 +1052,13 @@ impl Workspace {
|
|||
cx.emit(Event::WorkspaceCreated(weak_handle.clone()));
|
||||
let modal_layer = cx.new(|_| ModalLayer::new());
|
||||
let toast_layer = cx.new(|_| ToastLayer::new());
|
||||
cx.subscribe(
|
||||
&modal_layer,
|
||||
|_, _, _: &modal_layer::ModalOpenedEvent, cx| {
|
||||
cx.emit(Event::ModalOpened);
|
||||
},
|
||||
)
|
||||
.detach();
|
||||
|
||||
let bottom_dock_layout = WorkspaceSettings::get_global(cx).bottom_dock_layout;
|
||||
let left_dock = Dock::new(DockPosition::Left, modal_layer.clone(), window, cx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue