Fix missing actions in the command palette
Previously, the workspace view was on the stack when we were computing the available actions, which excluded it. This is a stopgap. We should find a better solution ASAP.
This commit is contained in:
parent
bce51c521a
commit
e6604d1641
2 changed files with 15 additions and 6 deletions
|
@ -2,7 +2,7 @@ use collections::CommandPaletteFilter;
|
||||||
use fuzzy::{StringMatch, StringMatchCandidate};
|
use fuzzy::{StringMatch, StringMatchCandidate};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, elements::*, keymap_matcher::Keystroke, Action, AppContext, Element, MouseState,
|
actions, elements::*, keymap_matcher::Keystroke, Action, AppContext, Element, MouseState,
|
||||||
ViewContext,
|
ViewContext, WindowContext,
|
||||||
};
|
};
|
||||||
use picker::{Picker, PickerDelegate, PickerEvent};
|
use picker::{Picker, PickerDelegate, PickerEvent};
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
|
@ -45,15 +45,19 @@ fn toggle_command_palette(_: &mut Workspace, _: &Toggle, cx: &mut ViewContext<Wo
|
||||||
let workspace = cx.handle();
|
let workspace = cx.handle();
|
||||||
let focused_view_id = cx.focused_view_id().unwrap_or_else(|| workspace.id());
|
let focused_view_id = cx.focused_view_id().unwrap_or_else(|| workspace.id());
|
||||||
|
|
||||||
cx.defer(move |workspace, cx| {
|
cx.window_context().defer(move |cx| {
|
||||||
workspace.toggle_modal(cx, |_, cx| {
|
// Build the delegate before the workspace is put on the stack so we can find it when
|
||||||
cx.add_view(|cx| Picker::new(CommandPaletteDelegate::new(focused_view_id, cx), cx))
|
// computing the actions. We should really not allow available_actions to be called
|
||||||
});
|
// if it's not reliable however.
|
||||||
|
let delegate = CommandPaletteDelegate::new(focused_view_id, cx);
|
||||||
|
workspace.update(cx, |workspace, cx| {
|
||||||
|
workspace.toggle_modal(cx, |_, cx| cx.add_view(|cx| Picker::new(delegate, cx)));
|
||||||
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CommandPaletteDelegate {
|
impl CommandPaletteDelegate {
|
||||||
pub fn new(focused_view_id: usize, cx: &mut ViewContext<Picker<Self>>) -> Self {
|
pub fn new(focused_view_id: usize, cx: &mut WindowContext) -> Self {
|
||||||
let actions = cx
|
let actions = cx
|
||||||
.available_actions(focused_view_id)
|
.available_actions(focused_view_id)
|
||||||
.filter_map(|(name, action, bindings)| {
|
.filter_map(|(name, action, bindings)| {
|
||||||
|
|
|
@ -444,6 +444,11 @@ impl<'a> WindowContext<'a> {
|
||||||
.map(|action_type| (action_type, depth)),
|
.map(|action_type| (action_type, depth)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log::error!(
|
||||||
|
"view {} not found when computing available actions",
|
||||||
|
view_id
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue