diff options
author | Jan Hrastnik | 2020-10-24 11:36:34 +0000 |
---|---|---|
committer | Jan Hrastnik | 2020-10-24 11:36:34 +0000 |
commit | a123cf37a0d8a60146c82b898ab8da9f56276b17 (patch) | |
tree | 29336dbfc31ff0127360f64ee00c609f22d49238 /helix-view/src | |
parent | 8f37c26f350b6409d7e13eb7fee4ef241dd4af5c (diff) |
several fixes
Diffstat (limited to 'helix-view/src')
-rw-r--r-- | helix-view/src/prompt.rs | 20 |
1 files changed, 12 insertions, 8 deletions
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<Vec<String>> + 'static, + mut completion_fn: impl FnMut(&str) -> Option<Vec<String>> + 'static, callback_fn: impl FnMut(&mut Editor, &str) + 'static, - command_list: Vec<String>, ) -> 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) { |