mirror of https://github.com/helix-editor/helix
refactor: remove unneeded macro
parent
24bd14863b
commit
4fabd7927d
|
@ -16,7 +16,7 @@ mod text_decorations;
|
||||||
|
|
||||||
use crate::compositor::{Compositor, Context};
|
use crate::compositor::{Compositor, Context};
|
||||||
use crate::job::{self, Callback};
|
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 completion::Completion;
|
||||||
pub use editor::EditorView;
|
pub use editor::EditorView;
|
||||||
use helix_core::hashmap;
|
use helix_core::hashmap;
|
||||||
|
@ -418,10 +418,9 @@ pub fn file_explorer(cursor: Option<u32>, root: PathBuf, editor: &Editor) -> Res
|
||||||
)
|
)
|
||||||
.with_cursor(cursor.unwrap_or_default())
|
.with_cursor(cursor.unwrap_or_default())
|
||||||
.with_preview(|_editor, (path, _is_dir)| Some((path.as_path().into(), None)))
|
.with_preview(|_editor, (path, _is_dir)| Some((path.as_path().into(), None)))
|
||||||
.with_key_handlers(declare_key_handlers! {
|
.with_key_handlers(hashmap! {
|
||||||
|cx, (path, _is_dir): &(PathBuf, bool), cursor|,
|
|
||||||
// create
|
// create
|
||||||
alt!('n') => {
|
alt!('n') => Box::new(|cx: &mut Context, (path, _is_dir): &(PathBuf, bool), cursor: u32| {
|
||||||
create_file_operation_prompt(
|
create_file_operation_prompt(
|
||||||
cursor,
|
cursor,
|
||||||
"create:",
|
"create:",
|
||||||
|
@ -472,9 +471,9 @@ pub fn file_explorer(cursor: Option<u32>, root: PathBuf, editor: &Editor) -> Res
|
||||||
|
|
||||||
create_op(cursor, cx, root, to_create_str, &to_create)
|
create_op(cursor, cx, root, to_create_str, &to_create)
|
||||||
})
|
})
|
||||||
},
|
}) as Box<dyn Fn(&mut Context, &(PathBuf, bool), u32) + 'static>,
|
||||||
// move
|
// move
|
||||||
alt!('m') => {
|
alt!('m') => Box::new(|cx: &mut Context, (path, _is_dir): &(PathBuf, bool), cursor: u32|{
|
||||||
create_file_operation_prompt(
|
create_file_operation_prompt(
|
||||||
cursor,
|
cursor,
|
||||||
"move:",
|
"move:",
|
||||||
|
@ -523,9 +522,9 @@ pub fn file_explorer(cursor: Option<u32>, root: PathBuf, editor: &Editor) -> Res
|
||||||
|
|
||||||
move_op(cursor, cx, root, move_to_str, move_from)
|
move_op(cursor, cx, root, move_to_str, move_from)
|
||||||
})
|
})
|
||||||
},
|
}) as Box<dyn Fn(&mut Context, &(PathBuf, bool), u32) + 'static>,
|
||||||
// delete
|
// delete
|
||||||
alt!('d') => {
|
alt!('d') => Box::new(|cx: &mut Context, (path, _is_dir): &(PathBuf, bool), cursor: u32|{
|
||||||
create_file_operation_prompt(
|
create_file_operation_prompt(
|
||||||
cursor,
|
cursor,
|
||||||
"delete? (y/n):",
|
"delete? (y/n):",
|
||||||
|
@ -567,9 +566,9 @@ pub fn file_explorer(cursor: Option<u32>, root: PathBuf, editor: &Editor) -> Res
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
}) as Box<dyn Fn(&mut Context, &(PathBuf, bool), u32) + 'static>,
|
||||||
// copy file / directory
|
// copy file / directory
|
||||||
alt!('c') => {
|
alt!('c') => Box::new(|cx: &mut Context, (path, _is_dir): &(PathBuf, bool), cursor: u32|{
|
||||||
create_file_operation_prompt(
|
create_file_operation_prompt(
|
||||||
cursor,
|
cursor,
|
||||||
"copy-to:",
|
"copy-to:",
|
||||||
|
@ -618,9 +617,9 @@ pub fn file_explorer(cursor: Option<u32>, root: PathBuf, editor: &Editor) -> Res
|
||||||
copy_op(cursor, cx, root, copy_to_str, copy_from)
|
copy_op(cursor, cx, root, copy_to_str, copy_from)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
}) as Box<dyn Fn(&mut Context, &(PathBuf, bool), u32) + 'static>,
|
||||||
// copy path into register
|
// 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(
|
let register = cx.editor.selected_register.unwrap_or(
|
||||||
cx.editor.config().default_yank_register
|
cx.editor.config().default_yank_register
|
||||||
);
|
);
|
||||||
|
@ -632,7 +631,7 @@ pub fn file_explorer(cursor: Option<u32>, root: PathBuf, editor: &Editor) -> Res
|
||||||
Ok(()) => cx.editor.set_status(message),
|
Ok(()) => cx.editor.set_status(message),
|
||||||
Err(err) => cx.editor.set_error(err.to_string())
|
Err(err) => cx.editor.set_error(err.to_string())
|
||||||
};
|
};
|
||||||
}
|
}) as Box<dyn Fn(&mut Context, &(PathBuf, bool), u32) + 'static>
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(picker)
|
Ok(picker)
|
||||||
|
|
|
@ -1186,16 +1186,3 @@ impl<T: 'static + Send + Sync, D> Drop for Picker<T, D> {
|
||||||
|
|
||||||
type PickerCallback<T> = Box<dyn Fn(&mut Context, &T, Action)>;
|
type PickerCallback<T> = Box<dyn Fn(&mut Context, &T, Action)>;
|
||||||
pub type PickerKeyHandler<T> = HashMap<KeyEvent, Box<dyn Fn(&mut Context, &T, u32) + 'static>>;
|
pub type PickerKeyHandler<T> = HashMap<KeyEvent, Box<dyn Fn(&mut Context, &T, u32) + 'static>>;
|
||||||
|
|
||||||
/// 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<dyn Fn(&mut Context, $t, u32) + 'static>
|
|
||||||
),*
|
|
||||||
)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue