Do not dismiss buffer search when any modal is present

Co-authored-by: Piotr Osiewicz <piotr@zed.dev>
This commit is contained in:
Kirill Bulatov 2024-01-09 23:27:54 +02:00
parent a579ef17d7
commit 8b71b1d07b
3 changed files with 17 additions and 4 deletions

View file

@ -43,7 +43,7 @@ pub enum Event {
} }
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.observe_new_views(|editor: &mut Workspace, _| BufferSearchBar::register(editor)) cx.observe_new_views(|workspace: &mut Workspace, _| BufferSearchBar::register(workspace))
.detach(); .detach();
} }
@ -479,6 +479,11 @@ impl SearchActionsRegistrar for Workspace {
callback: fn(&mut BufferSearchBar, &A, &mut ViewContext<BufferSearchBar>), callback: fn(&mut BufferSearchBar, &A, &mut ViewContext<BufferSearchBar>),
) { ) {
self.register_action(move |workspace, action: &A, cx| { self.register_action(move |workspace, action: &A, cx| {
if workspace.has_active_modal(cx) {
cx.propagate();
return;
}
let pane = workspace.active_pane(); let pane = workspace.active_pane();
pane.update(cx, move |this, cx| { pane.update(cx, move |this, cx| {
this.toolbar().update(cx, move |this, cx| { this.toolbar().update(cx, move |this, cx| {
@ -539,11 +544,11 @@ impl BufferSearchBar {
this.select_all_matches(action, cx); this.select_all_matches(action, cx);
}); });
registrar.register_handler(|this, _: &editor::Cancel, cx| { registrar.register_handler(|this, _: &editor::Cancel, cx| {
if !this.dismissed { if this.dismissed {
this.dismiss(&Dismiss, cx);
return;
}
cx.propagate(); cx.propagate();
} else {
this.dismiss(&Dismiss, cx);
}
}); });
registrar.register_handler(|this, deploy, cx| { registrar.register_handler(|this, deploy, cx| {
this.deploy(deploy, cx); this.deploy(deploy, cx);

View file

@ -101,6 +101,10 @@ impl ModalLayer {
let active_modal = self.active_modal.as_ref()?; let active_modal = self.active_modal.as_ref()?;
active_modal.modal.view().downcast::<V>().ok() active_modal.modal.view().downcast::<V>().ok()
} }
pub fn has_active_modal(&self) -> bool {
self.active_modal.is_some()
}
} }
impl Render for ModalLayer { impl Render for ModalLayer {

View file

@ -3383,6 +3383,10 @@ impl Workspace {
div div
} }
pub fn has_active_modal(&self, cx: &WindowContext<'_>) -> bool {
self.modal_layer.read(cx).has_active_modal()
}
pub fn active_modal<V: ManagedView + 'static>( pub fn active_modal<V: ManagedView + 'static>(
&mut self, &mut self,
cx: &ViewContext<Self>, cx: &ViewContext<Self>,