From a123cf37a0d8a60146c82b898ab8da9f56276b17 Mon Sep 17 00:00:00 2001 From: Jan Hrastnik Date: Sat, 24 Oct 2020 13:36:34 +0200 Subject: several fixes --- helix-view/src/prompt.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'helix-view/src') diff --git a/helix-view/src/prompt.rs b/helix-view/src/prompt.rs index 032bbe54..e368fda8 100644 --- a/helix-view/src/prompt.rs +++ b/helix-view/src/prompt.rs @@ -16,15 +16,14 @@ pub struct Prompt { impl Prompt { pub fn new( prompt: String, - completion_fn: impl FnMut(&str) -> Option> + 'static, + mut completion_fn: impl FnMut(&str) -> Option> + 'static, callback_fn: impl FnMut(&mut Editor, &str) + 'static, - command_list: Vec, ) -> Prompt { Prompt { prompt, line: String::new(), cursor: 0, - completion: Some(command_list), + completion: completion_fn(""), should_close: false, completion_selection_index: None, completion_fn: Box::new(completion_fn), @@ -67,11 +66,16 @@ impl Prompt { } pub fn change_completion_selection(&mut self) { - if self.completion_selection_index.is_none() { - self.completion_selection_index = Some(0) - } else { - self.completion_selection_index = Some(self.completion_selection_index.unwrap() + 1) - } + self.completion_selection_index = self + .completion_selection_index + .map(|i| { + if i == self.completion.as_ref().unwrap().len() - 1 { + 0 + } else { + i + 1 + } + }) + .or(Some(0)) } pub fn handle_input(&mut self, key_event: KeyEvent, editor: &mut Editor) { -- cgit v1.2.3-70-g09d2