Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/ui/picker.rs')
| -rw-r--r-- | helix-term/src/ui/picker.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 3f3aaba2..a6a0e17c 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -258,6 +258,7 @@ pub struct Picker<T: 'static + Send + Sync, D: 'static> { widths: Vec<Constraint>, callback_fn: PickerCallback<T>, + default_action: Action, pub truncate_start: bool, /// Caches paths to documents @@ -382,6 +383,7 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> { truncate_start: true, show_preview: true, callback_fn: Box::new(callback_fn), + default_action: Action::Replace, completion_height: 0, widths, preview_cache: HashMap::new(), @@ -440,6 +442,11 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> { self } + pub fn with_default_action(mut self, action: Action) -> Self { + self.default_action = action; + self + } + /// Move the cursor by a number of lines, either down (`Forward`) or up (`Backward`) pub fn move_by(&mut self, amount: u32, direction: Direction) { let len = self.matcher.snapshot().matched_item_count(); @@ -1071,7 +1078,7 @@ impl<I: 'static + Send + Sync, D: 'static + Send + Sync> Component for Picker<I, key!(Esc) | ctrl!('c') => return close_fn(self), alt!(Enter) => { if let Some(option) = self.selection() { - (self.callback_fn)(ctx, option, Action::Replace); + (self.callback_fn)(ctx, option, self.default_action); } } key!(Enter) => { @@ -1095,7 +1102,7 @@ impl<I: 'static + Send + Sync, D: 'static + Send + Sync> Component for Picker<I, self.handle_prompt_change(true); } else { if let Some(option) = self.selection() { - (self.callback_fn)(ctx, option, Action::Replace); + (self.callback_fn)(ctx, option, self.default_action); } if let Some(history_register) = self.prompt.history_register() { if let Err(err) = ctx |