Add command palette filter global and update it when vim mode is enabled/disabled
This commit is contained in:
parent
431d71fe92
commit
f6292437fa
6 changed files with 39 additions and 6 deletions
|
@ -8,6 +8,7 @@ path = "src/command_palette.rs"
|
|||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
collections = { path = "../collections" }
|
||||
editor = { path = "../editor" }
|
||||
fuzzy = { path = "../fuzzy" }
|
||||
gpui = { path = "../gpui" }
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use collections::HashSet;
|
||||
use fuzzy::{StringMatch, StringMatchCandidate};
|
||||
use gpui::{
|
||||
actions,
|
||||
|
@ -10,6 +11,11 @@ use settings::Settings;
|
|||
use std::cmp;
|
||||
use workspace::Workspace;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct CommandPaletteFilter {
|
||||
pub filtered_namespaces: HashSet<&'static str>,
|
||||
}
|
||||
|
||||
pub fn init(cx: &mut MutableAppContext) {
|
||||
cx.add_action(CommandPalette::toggle);
|
||||
Picker::<CommandPalette>::init(cx);
|
||||
|
@ -45,14 +51,24 @@ impl CommandPalette {
|
|||
let this = cx.weak_handle();
|
||||
let actions = cx
|
||||
.available_actions(cx.window_id(), focused_view_id)
|
||||
.map(|(name, action, bindings)| Command {
|
||||
name: humanize_action_name(name),
|
||||
action,
|
||||
keystrokes: bindings
|
||||
.last()
|
||||
.map_or(Vec::new(), |binding| binding.keystrokes().to_vec()),
|
||||
.filter_map(|(name, action, bindings)| {
|
||||
if cx.has_global::<CommandPaletteFilter>() {
|
||||
let filter = cx.global::<CommandPaletteFilter>();
|
||||
if filter.filtered_namespaces.contains(action.namespace()) {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
Some(Command {
|
||||
name: humanize_action_name(name),
|
||||
action,
|
||||
keystrokes: bindings
|
||||
.last()
|
||||
.map_or(Vec::new(), |binding| binding.keystrokes().to_vec()),
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
let picker = cx.add_view(|cx| Picker::new(this, cx));
|
||||
Self {
|
||||
picker,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue