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.

Fix `workspace::ReopenLastPicker` action when `which_key` helper is enabled (#61002)

David4ebc1545d299
diff --git a/crates/workspace/src/modal_layer.rs b/crates/workspace/src/modal_layer.rs
index 4964d82159f..ec0254868b3 100644
--- a/crates/workspace/src/modal_layer.rs
+++ b/crates/workspace/src/modal_layer.rs
@@ -114,6 +114,11 @@ pub struct ModalLayer {
// can reveal it again with its exact prior state. Left intact across
// non-reopenable modals (e.g. the command palette), which may trigger the reopen.
stashed_modal: Option<Box<dyn ModalViewHandle>>,
+ // Set when a reveal was requested while another modal was still active (e.g. the
+ // which-key popup that is dismissed only after the reopen action fires). The reveal
+ // then happens once that modal closes, so it doesn't matter whether the triggering
+ // modal is dismissed before or after the action dispatches.
+ reveal_stash_when_free: bool,
dismiss_on_focus_lost: bool,
}
@@ -132,6 +137,7 @@ impl ModalLayer {
Self {
active_modal: None,
stashed_modal: None,
+ reveal_stash_when_free: false,
dismiss_on_focus_lost: false,
}
}
@@ -148,6 +154,9 @@ impl ModalLayer {
V: ModalView,
B: FnOnce(&mut Window, &mut Context<V>) -> V,
{
+ // Opening a modal explicitly supersedes any reveal that was waiting for the
+ // layer to become free.
+ self.reveal_stash_when_free = false;
if let Some(active_modal) = &self.active_modal {
let should_close = active_modal.modal.view().downcast::<V>().is_ok();
let did_close = self.hide_modal(window, cx);
@@ -193,7 +202,13 @@ impl ModalLayer {
/// Reveals the most recently stashed reopenable modal, if any. Returns whether
/// a modal was revealed.
pub fn reveal_stashed_modal(&mut self, window: &mut Window, cx: &mut Context<Self>) -> bool {
+ if self.stashed_modal.is_none() {
+ return false;
+ }
if self.active_modal.is_some() {
+ // Another modal is still closing (e.g. the which-key popup that dismisses
+ // only after this action fires). Reveal once it is gone; see `hide_modal`.
+ self.reveal_stash_when_free = true;
return false;
}
let Some(modal) = self.stashed_modal.take() else {
@@ -243,6 +258,12 @@ impl ModalLayer {
cx.notify();
}
self.dismiss_on_focus_lost = false;
+ // A reveal was requested while this modal was still active; now that the layer
+ // is free, honor it.
+ if self.reveal_stash_when_free && self.active_modal.is_none() {
+ self.reveal_stash_when_free = false;
+ self.reveal_stashed_modal(window, cx);
+ }
true
}
diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs
index 525a3d4d29b..eb454d9c64c 100644
--- a/crates/workspace/src/workspace.rs
+++ b/crates/workspace/src/workspace.rs
@@ -14851,6 +14851,50 @@ mod tests {
);
}
+ #[gpui::test]
+ async fn test_reopen_last_picker_with_active_leader_modal(cx: &mut gpui::TestAppContext) {
+ init_test(cx);
+
+ let fs = FakeFs::new(cx.executor());
+ let project = Project::test(fs, [], cx).await;
+ let (workspace, cx) =
+ cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
+
+ // Stash a reopenable modal.
+ workspace.update_in(cx, |workspace, window, cx| {
+ workspace.toggle_modal(window, cx, ReopenableTestModal::new);
+ });
+ cx.executor().run_until_parked();
+ workspace.update_in(cx, |workspace, window, cx| {
+ workspace
+ .modal_layer
+ .update(cx, |modal_layer, cx| modal_layer.hide_modal(window, cx));
+ });
+ cx.executor().run_until_parked();
+
+ // A non-reopenable modal (e.g. the which-key popup) is already
+ // active when the reopen fires, and it dismisses *after* the action rather
+ // than before it (which-key dismisses when pending input clears).
+ workspace.update_in(cx, |workspace, window, cx| {
+ workspace.toggle_modal(window, cx, TestModal::new);
+ });
+ cx.executor().run_until_parked();
+ workspace.update_in(cx, |workspace, window, cx| {
+ // Reopen fires first (chord completes and dispatches the action)...
+ workspace.reopen_last_picker(&ReopenLastPicker, window, cx);
+ // ...then the modal dismisses
+ let modal = workspace.active_modal::<TestModal>(cx).unwrap();
+ modal.update(cx, |_, cx| cx.emit(DismissEvent));
+ });
+ cx.executor().run_until_parked();
+ assert!(
+ workspace.read_with(cx, |workspace, cx| workspace
+ .active_modal::<ReopenableTestModal>(cx)
+ .is_some()),
+ "reopen with an active modal that dismisses after the action should reveal the stash"
+ );
+ }
+
#[gpui::test]
async fn test_panels(cx: &mut gpui::TestAppContext) {
init_test(cx);