Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions crates/command_palette/src/command_palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,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)
Expand Down Expand Up @@ -560,6 +563,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;
};
Expand Down Expand Up @@ -863,6 +869,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);
Expand Down
Loading