Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
command_palette: Fix showing keybinding in footer actions on zero matches (#54519)
galuis116d4163c70311e
diff --git a/crates/command_palette/src/command_palette.rs b/crates/command_palette/src/command_palette.rsindex d0c7f052f4d..68d04537a02 100644--- a/crates/command_palette/src/command_palette.rs+++ b/crates/command_palette/src/command_palette.rs@@ -354,6 +354,9 @@ impl CommandPaletteDelegate {}fn selected_command(&self) -> Option<&Command> {+ if self.matches.is_empty() {+ return None;+ }let action_ix = self.matches.get(self.selected_ix)@@ -556,6 +559,9 @@ impl PickerDelegate for CommandPaletteDelegate {fn confirm(&mut self, secondary: bool, window: &mut Window, cx: &mut Context<Picker<Self>>) {if secondary {+ if self.matches.is_empty() {+ return;+ }let Some(selected_command) = self.selected_command() else {return;};@@ -859,6 +865,33 @@ mod tests {assert!(palette.delegate.matches.is_empty())});}++ #[gpui::test]+ async fn test_selected_command_none_when_no_matches(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, |mw, _| mw.workspace().clone());++ cx.simulate_keystrokes("cmd-shift-p");+ let picker = workspace.update(cx, |workspace, cx| {+ workspace+ .active_modal::<CommandPalette>(cx)+ .unwrap()+ .read(cx)+ .picker+ .clone()+ });++ cx.simulate_input("definitely-no-command-should-match-this");+ cx.background_executor.run_until_parked();++ picker.read_with(cx, |picker, _cx| {+ assert!(picker.delegate.matches.is_empty());+ assert!(picker.delegate.selected_command().is_none());+ });+ }#[gpui::test]async fn test_normalized_matches(cx: &mut TestAppContext) {let app_state = init_test(cx);