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 reopening and interacting with the command palette when its submenu is already open closing the palette (#54243)

prayansh_chhablani250022469dd5
diff --git a/crates/command_palette/src/command_palette.rs b/crates/command_palette/src/command_palette.rs
index e1eddf01c28..42236ea0a98 100644
--- a/crates/command_palette/src/command_palette.rs
+++ b/crates/command_palette/src/command_palette.rs
@@ -83,6 +83,15 @@ impl CommandPalette {
window: &mut Window,
cx: &mut Context<Workspace>,
) {
+ if workspace.active_modal::<CommandPalette>(cx).is_some() {
+ workspace.hide_modal(window, cx);
+ return;
+ }
+
+ if workspace.has_active_modal(window, cx) && !workspace.hide_modal(window, cx) {
+ return;
+ }
+
let Some(previous_focus_handle) = window.focused(cx) else {
return;
};
@@ -1031,6 +1040,28 @@ mod tests {
});
}
+ #[gpui::test]
+ async fn test_reopen_command_palette_over_another_modal(cx: &mut TestAppContext) {
+ let app_state = init_test(cx);
+ let project = Project::test(app_state.fs.clone(), [], cx).await;
+ let (multi_workspace, cx) =
+ cx.add_window_view(|window, cx| MultiWorkspace::test_new(project.clone(), window, cx));
+ let workspace =
+ multi_workspace.read_with(cx, |multi_workspace, _| multi_workspace.workspace().clone());
+
+ cx.simulate_keystrokes("cmd-n");
+
+ for _ in 0..2 {
+ cx.simulate_keystrokes("cmd-shift-p");
+ cx.simulate_input("go to line: Toggle");
+ cx.simulate_keystrokes("enter");
+
+ workspace.update(cx, |workspace, cx| {
+ assert!(workspace.active_modal::<GoToLine>(cx).is_some());
+ });
+ }
+ }
+
fn init_test(cx: &mut TestAppContext) -> Arc<AppState> {
cx.update(|cx| {
let app_state = AppState::test(cx);