Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

workspace: Fix captured focus when opening modals (#63512)

Matei Oprea837264129f6f
diff --git a/crates/workspace/src/modal_layer.rs b/crates/workspace/src/modal_layer.rs
index ec0254868b3..884db6567ae 100644
--- a/crates/workspace/src/modal_layer.rs
+++ b/crates/workspace/src/modal_layer.rs
@@ -157,15 +157,17 @@ impl ModalLayer {
// Opening a modal explicitly supersedes any reveal that was waiting for the
// layer to become free.
self.reveal_stash_when_free = false;
+ let mut previous_focus_handle = window.focused(cx);
if let Some(active_modal) = &self.active_modal {
let should_close = active_modal.modal.view().downcast::<V>().is_ok();
+ previous_focus_handle = active_modal.previous_focus_handle.clone();
let did_close = self.hide_modal(window, cx);
if should_close || !did_close {
return;
}
}
let new_modal = cx.new(|cx| build_view(window, cx));
- self.show_modal(Box::new(new_modal), window, cx);
+ self.show_modal(Box::new(new_modal), previous_focus_handle, window, cx);
cx.emit(ModalOpenedEvent);
}
@@ -174,6 +176,7 @@ impl ModalLayer {
fn show_modal(
&mut self,
modal: Box<dyn ModalViewHandle>,
+ previous_focus_handle: Option<FocusHandle>,
window: &mut Window,
cx: &mut Context<Self>,
) {
@@ -190,7 +193,7 @@ impl ModalLayer {
}
}),
],
- previous_focus_handle: window.focused(cx),
+ previous_focus_handle,
focus_handle,
});
cx.defer_in(window, move |_, window, cx| {
@@ -214,7 +217,8 @@ impl ModalLayer {
let Some(modal) = self.stashed_modal.take() else {
return false;
};
- self.show_modal(modal, window, cx);
+ let previous_focus_handle = window.focused(cx);
+ self.show_modal(modal, previous_focus_handle, window, cx);
cx.emit(ModalOpenedEvent);
true
}