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
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -917,6 +917,7 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
|
||||||
name = "command_palette"
|
name = "command_palette"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"collections",
|
||||||
"ctor",
|
"ctor",
|
||||||
"editor",
|
"editor",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
|
@ -5601,6 +5602,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"assets",
|
"assets",
|
||||||
"collections",
|
"collections",
|
||||||
|
"command_palette",
|
||||||
"editor",
|
"editor",
|
||||||
"gpui",
|
"gpui",
|
||||||
"indoc",
|
"indoc",
|
||||||
|
|
|
@ -8,6 +8,7 @@ path = "src/command_palette.rs"
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
collections = { path = "../collections" }
|
||||||
editor = { path = "../editor" }
|
editor = { path = "../editor" }
|
||||||
fuzzy = { path = "../fuzzy" }
|
fuzzy = { path = "../fuzzy" }
|
||||||
gpui = { path = "../gpui" }
|
gpui = { path = "../gpui" }
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use collections::HashSet;
|
||||||
use fuzzy::{StringMatch, StringMatchCandidate};
|
use fuzzy::{StringMatch, StringMatchCandidate};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions,
|
actions,
|
||||||
|
@ -10,6 +11,11 @@ use settings::Settings;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct CommandPaletteFilter {
|
||||||
|
pub filtered_namespaces: HashSet<&'static str>,
|
||||||
|
}
|
||||||
|
|
||||||
pub fn init(cx: &mut MutableAppContext) {
|
pub fn init(cx: &mut MutableAppContext) {
|
||||||
cx.add_action(CommandPalette::toggle);
|
cx.add_action(CommandPalette::toggle);
|
||||||
Picker::<CommandPalette>::init(cx);
|
Picker::<CommandPalette>::init(cx);
|
||||||
|
@ -45,14 +51,24 @@ impl CommandPalette {
|
||||||
let this = cx.weak_handle();
|
let this = cx.weak_handle();
|
||||||
let actions = cx
|
let actions = cx
|
||||||
.available_actions(cx.window_id(), focused_view_id)
|
.available_actions(cx.window_id(), focused_view_id)
|
||||||
.map(|(name, action, bindings)| Command {
|
.filter_map(|(name, action, bindings)| {
|
||||||
name: humanize_action_name(name),
|
if cx.has_global::<CommandPaletteFilter>() {
|
||||||
action,
|
let filter = cx.global::<CommandPaletteFilter>();
|
||||||
keystrokes: bindings
|
if filter.filtered_namespaces.contains(action.namespace()) {
|
||||||
.last()
|
return None;
|
||||||
.map_or(Vec::new(), |binding| binding.keystrokes().to_vec()),
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(Command {
|
||||||
|
name: humanize_action_name(name),
|
||||||
|
action,
|
||||||
|
keystrokes: bindings
|
||||||
|
.last()
|
||||||
|
.map_or(Vec::new(), |binding| binding.keystrokes().to_vec()),
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let picker = cx.add_view(|cx| Picker::new(this, cx));
|
let picker = cx.add_view(|cx| Picker::new(this, cx));
|
||||||
Self {
|
Self {
|
||||||
picker,
|
picker,
|
||||||
|
|
|
@ -2,6 +2,7 @@ use std::any::{Any, TypeId};
|
||||||
|
|
||||||
pub trait Action: 'static {
|
pub trait Action: 'static {
|
||||||
fn id(&self) -> TypeId;
|
fn id(&self) -> TypeId;
|
||||||
|
fn namespace(&self) -> &'static str;
|
||||||
fn name(&self) -> &'static str;
|
fn name(&self) -> &'static str;
|
||||||
fn as_any(&self) -> &dyn Any;
|
fn as_any(&self) -> &dyn Any;
|
||||||
fn boxed_clone(&self) -> Box<dyn Action>;
|
fn boxed_clone(&self) -> Box<dyn Action>;
|
||||||
|
@ -80,6 +81,10 @@ macro_rules! impl_internal_actions {
|
||||||
macro_rules! __impl_action {
|
macro_rules! __impl_action {
|
||||||
($namespace:path, $name:ident, $from_json_fn:item) => {
|
($namespace:path, $name:ident, $from_json_fn:item) => {
|
||||||
impl $crate::action::Action for $name {
|
impl $crate::action::Action for $name {
|
||||||
|
fn namespace(&self) -> &'static str {
|
||||||
|
stringify!($namespace)
|
||||||
|
}
|
||||||
|
|
||||||
fn name(&self) -> &'static str {
|
fn name(&self) -> &'static str {
|
||||||
stringify!($name)
|
stringify!($name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ doctest = false
|
||||||
[dependencies]
|
[dependencies]
|
||||||
assets = { path = "../assets" }
|
assets = { path = "../assets" }
|
||||||
collections = { path = "../collections" }
|
collections = { path = "../collections" }
|
||||||
|
command_palette = { path = "../command_palette" }
|
||||||
editor = { path = "../editor" }
|
editor = { path = "../editor" }
|
||||||
gpui = { path = "../gpui" }
|
gpui = { path = "../gpui" }
|
||||||
language = { path = "../language" }
|
language = { path = "../language" }
|
||||||
|
|
|
@ -10,6 +10,7 @@ mod utils;
|
||||||
mod visual;
|
mod visual;
|
||||||
|
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
|
use command_palette::CommandPaletteFilter;
|
||||||
use editor::{Bias, CursorShape, Editor, Input};
|
use editor::{Bias, CursorShape, Editor, Input};
|
||||||
use gpui::{impl_actions, MutableAppContext, Subscription, ViewContext, WeakViewHandle};
|
use gpui::{impl_actions, MutableAppContext, Subscription, ViewContext, WeakViewHandle};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -124,6 +125,13 @@ impl Vim {
|
||||||
if enabled {
|
if enabled {
|
||||||
self.state.mode = Mode::Normal;
|
self.state.mode = Mode::Normal;
|
||||||
}
|
}
|
||||||
|
cx.update_default_global::<CommandPaletteFilter, _, _>(|filter, _| {
|
||||||
|
if enabled {
|
||||||
|
filter.filtered_namespaces.remove("vim");
|
||||||
|
} else {
|
||||||
|
filter.filtered_namespaces.insert("vim");
|
||||||
|
}
|
||||||
|
});
|
||||||
self.sync_editor_options(cx);
|
self.sync_editor_options(cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue