diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index d2cc6046f..7f056fe4e 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -16,7 +16,7 @@ mod text_decorations; use crate::compositor::{Compositor, Context}; use crate::job::{self, Callback}; -use crate::{alt, declare_key_handlers, filter_picker_entry}; +use crate::{alt, filter_picker_entry}; pub use completion::Completion; pub use editor::EditorView; use helix_core::hashmap; @@ -418,10 +418,9 @@ pub fn file_explorer(cursor: Option, root: PathBuf, editor: &Editor) -> Res ) .with_cursor(cursor.unwrap_or_default()) .with_preview(|_editor, (path, _is_dir)| Some((path.as_path().into(), None))) - .with_key_handlers(declare_key_handlers! { - |cx, (path, _is_dir): &(PathBuf, bool), cursor|, + .with_key_handlers(hashmap! { // create - alt!('n') => { + alt!('n') => Box::new(|cx: &mut Context, (path, _is_dir): &(PathBuf, bool), cursor: u32| { create_file_operation_prompt( cursor, "create:", @@ -472,9 +471,9 @@ pub fn file_explorer(cursor: Option, root: PathBuf, editor: &Editor) -> Res create_op(cursor, cx, root, to_create_str, &to_create) }) - }, + }) as Box, // move - alt!('m') => { + alt!('m') => Box::new(|cx: &mut Context, (path, _is_dir): &(PathBuf, bool), cursor: u32|{ create_file_operation_prompt( cursor, "move:", @@ -523,9 +522,9 @@ pub fn file_explorer(cursor: Option, root: PathBuf, editor: &Editor) -> Res move_op(cursor, cx, root, move_to_str, move_from) }) - }, + }) as Box, // delete - alt!('d') => { + alt!('d') => Box::new(|cx: &mut Context, (path, _is_dir): &(PathBuf, bool), cursor: u32|{ create_file_operation_prompt( cursor, "delete? (y/n):", @@ -567,9 +566,9 @@ pub fn file_explorer(cursor: Option, root: PathBuf, editor: &Editor) -> Res None } }) - }, + }) as Box, // copy file / directory - alt!('c') => { + alt!('c') => Box::new(|cx: &mut Context, (path, _is_dir): &(PathBuf, bool), cursor: u32|{ create_file_operation_prompt( cursor, "copy-to:", @@ -618,9 +617,9 @@ pub fn file_explorer(cursor: Option, root: PathBuf, editor: &Editor) -> Res copy_op(cursor, cx, root, copy_to_str, copy_from) } }) - }, + }) as Box, // copy path into register - alt!('y') => { + alt!('y') => Box::new(|cx: &mut Context, (path, _is_dir): &(PathBuf, bool), _cursor: u32|{ let register = cx.editor.selected_register.unwrap_or( cx.editor.config().default_yank_register ); @@ -632,7 +631,7 @@ pub fn file_explorer(cursor: Option, root: PathBuf, editor: &Editor) -> Res Ok(()) => cx.editor.set_status(message), Err(err) => cx.editor.set_error(err.to_string()) }; - } + }) as Box }); Ok(picker) diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index ac484c080..87937cc7b 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -1186,16 +1186,3 @@ impl Drop for Picker { type PickerCallback = Box; pub type PickerKeyHandler = HashMap>; - -/// Convenience macro to add custom keybindings per picker -#[macro_export] -macro_rules! declare_key_handlers { - (|$cx:ident, $item:tt : $t:ty, $cursor:ident|, $($key:expr => $handler:block),* $(,)?) => { - hashmap!( - $( - $key => Box::new(|$cx: &mut Context, $item: $t, $cursor: u32| $handler) - as Box - ),* - ) - }; - }