diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index ee8bbb32d..f1a9162c9 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, ctrl, filter_picker_entry}; +use crate::{alt, ctrl, declare_key_handlers, filter_picker_entry}; pub use completion::Completion; pub use editor::EditorView; use helix_core::hashmap; @@ -301,17 +301,6 @@ pub fn file_explorer(root: PathBuf, editor: &Editor) -> Result |$cx:ident, $path:ident| $handler:block),* $(,)?) => { - hashmap!( - $( - $key => Box::new(|$cx: &mut Context, $path: &(PathBuf, bool)| $handler) - as Box - ),* - ) - }; - } - let picker = Picker::new( columns, 0, @@ -342,16 +331,30 @@ pub fn file_explorer(root: PathBuf, editor: &Editor) -> Result |cx, path| { + // TODO: add a way to get user input in the Picker component and then + // execute an action based on that. Maybe re-use the existing Prompt component somehow? + |cx, path: &(PathBuf, bool)|, + // create + alt!('c') => { + // TODO: ask user for name of file to be created + // Fill in with the picker's current directory log::error!("create file"); }, - "Rename" alt!('r') => |cx, path| { + // move + alt!('m') => { + // TODO: ask the user for new name of file + // on enter move the file to the new location log::error!("rename file"); }, - "Delete" alt!('d') => |cx, path| { + // delete + alt!('d') => { + // TODO: ask user for confirmation, while showing which file + // will be deleted log::error!("delete file"); }, - "Copy" alt!('y') => |cx, path| { + // copy + alt!('y') => { + // TODO: ask the user for new name of file log::error!("copy file"); }, }); diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 7bc998bfe..4ddeafd3b 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -1182,3 +1182,16 @@ 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:ident : $t:ty|, $($key:expr => $handler:block),* $(,)?) => { + hashmap!( + $( + $key => Box::new(|$cx: &mut Context, $item: $t| $handler) + as Box + ),* + ) + }; + }