@@ -44,7 +44,7 @@ use movement::Movement;
44use crate::{
44use crate::{
46 compositor::{self, Component, Compositor},
46 compositor::{self, Component, Compositor},
47− ui::{self, overlay::overlayed, FilePicker, Popup, Prompt, PromptEvent},
47+ ui::{self, overlay::overlayed, FilePicker, Picker, Popup, Prompt, PromptEvent},
50use crate::job::{self, Job, Jobs};
50use crate::job::{self, Job, Jobs};
@@ -430,6 +430,7 @@ impl MappableCommand {
430 decrement, "Decrement",
430 decrement, "Decrement",
431 record_macro, "Record macro",
431 record_macro, "Record macro",
432 replay_macro, "Replay macro",
432 replay_macro, "Replay macro",
433+ command_palette, "Open command pallete",
@@ -3692,6 +3693,69 @@ pub fn code_action(cx: &mut Context) {
3696+pub fn command_palette(cx: &mut Context) {
3697+ cx.callback = Some(Box::new(
3698+ move |compositor: &mut Compositor, cx: &mut compositor::Context| {
3699+ let doc = doc_mut!(cx.editor);
3701+ compositor.find::<ui::EditorView>().unwrap().keymaps[&doc.mode].reverse_map();
3703+ let mut commands: Vec<MappableCommand> = MappableCommand::STATIC_COMMAND_LIST.into();
3705+ cmd::TYPABLE_COMMAND_LIST
3707+ .map(|cmd| MappableCommand::Typable {
3708+ name: cmd.name.to_owned(),
3709+ doc: cmd.doc.to_owned(),
3714+ // formats key bindings, multiple bindings are comma separated,
3715+ // individual key presses are joined with `+`
3716+ let fmt_binding = |bindings: &Vec<Vec<KeyEvent>>| -> String {
3721+ .map(|key| key.to_string())
3722+ .collect::<Vec<String>>()
3725+ .collect::<Vec<String>>()
3729+ let picker = Picker::new(
3731+ move |command| match command {
3732+ MappableCommand::Typable { doc, name, .. } => match keymap.get(name as &String)
3734+ Some(bindings) => format!("{} ({})", doc, fmt_binding(bindings)).into(),
3735+ None => doc.into(),
3737+ MappableCommand::Static { doc, name, .. } => match keymap.get(*name) {
3738+ Some(bindings) => format!("{} ({})", doc, fmt_binding(bindings)).into(),
3739+ None => (*doc).into(),
3742+ move |cx, command, _action| {
3743+ let mut ctx = Context {
3745+ count: std::num::NonZeroUsize::new(1),
3748+ on_next_key_callback: None,
3751+ command.execute(&mut ctx);
3754+ compositor.push(Box::new(picker));
3695pub fn execute_lsp_command(editor: &mut Editor, cmd: lsp::Command) {
3759pub fn execute_lsp_command(editor: &mut Editor, cmd: lsp::Command) {
3696 let doc = doc!(editor);
3760 let doc = doc!(editor);
3697 let language_server = match doc.language_server() {
3761 let language_server = match doc.language_server() {