From 06502e5a2e18eeb0e6c4828b6cda0d4ba81cdbab Mon Sep 17 00:00:00 2001 From: Jan Hrastnik Date: Mon, 19 Oct 2020 19:39:35 +0200 Subject: added prompt close --- helix-term/src/application.rs | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'helix-term/src/application.rs') diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 87d03c72..8972f082 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -235,7 +235,14 @@ impl Renderer { .set_string(1, self.size.1 - 2, mode, self.text_color); } - pub fn render_prompt(&mut self, prompt: &Prompt) { + pub fn render_prompt(&mut self, view: &View, prompt: &Prompt) { + // completion + if prompt.completion.is_some() { + self.surface.set_style( + Rect::new(0, self.size.1 - 6, self.size.0, 4), + view.theme.get("ui.statusline"), + ); + } // render buffer text self.surface .set_string(1, self.size.1 - 1, &prompt.prompt, self.text_color); @@ -309,10 +316,13 @@ impl Application { if let Some(view) = &mut self.editor.view { self.terminal.render_view(view, viewport); - } - - if let Some(prompt) = &self.prompt { - self.terminal.render_prompt(prompt); + if let Some(prompt) = &self.prompt { + if prompt.should_close { + self.prompt = None; + } else { + self.terminal.render_prompt(view, prompt); + } + } } self.terminal.draw(); @@ -383,7 +393,23 @@ impl Application { { let prompt = Prompt::new( ":".to_owned(), - |_input: &str| None, // completion + |_input: &str| { + let placeholder_list = vec![ + String::from("aaa"), + String::from("bbb"), + String::from("ccc"), + ]; + let mut matches = vec![]; + for command in placeholder_list { + if command.contains(_input) { + matches.push(command); + } + } + if matches.len() != 0 { + return Some(matches); + } + None + }, // completion |editor: &mut Editor, input: &str| match input { "q" => editor.should_close = true, _ => (), -- cgit v1.2.3-70-g09d2 From f3ddb8631f1e551fb3713c8eb20a0fdb2db2295d Mon Sep 17 00:00:00 2001 From: Jan Hrastnik Date: Mon, 19 Oct 2020 20:08:47 +0200 Subject: wip completion --- helix-term/src/application.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'helix-term/src/application.rs') diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 8972f082..4e6123ae 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -238,10 +238,28 @@ impl Renderer { pub fn render_prompt(&mut self, view: &View, prompt: &Prompt) { // completion if prompt.completion.is_some() { + let completion = prompt.completion.clone().unwrap(); + // TODO: find out better way of clearing individual lines of the screen + for i in (3..7) { + self.surface.set_string( + 0, + self.size.1 - i, + " ".repeat(self.size.0 as usize), + self.text_color, + ); + } self.surface.set_style( Rect::new(0, self.size.1 - 6, self.size.0, 4), view.theme.get("ui.statusline"), ); + for i in (0..completion.len()) { + self.surface.set_string( + 1, + self.size.1 - 6 + i as u16, + &completion[i], + self.text_color, + ) + } } // render buffer text self.surface @@ -395,6 +413,7 @@ impl Application { ":".to_owned(), |_input: &str| { let placeholder_list = vec![ + String::from("q"), String::from("aaa"), String::from("bbb"), String::from("ccc"), -- cgit v1.2.3-70-g09d2 From 8f37c26f350b6409d7e13eb7fee4ef241dd4af5c Mon Sep 17 00:00:00 2001 From: Jan Hrastnik Date: Tue, 20 Oct 2020 23:02:02 +0200 Subject: completion highlighting --- helix-term/src/application.rs | 36 ++++++++++++++++++++++++++++-------- helix-view/src/prompt.rs | 19 +++++++++++++++---- 2 files changed, 43 insertions(+), 12 deletions(-) (limited to 'helix-term/src/application.rs') diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 4e6123ae..75ebcb58 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -243,7 +243,7 @@ impl Renderer { for i in (3..7) { self.surface.set_string( 0, - self.size.1 - i, + self.size.1 - i as u16, " ".repeat(self.size.0 as usize), self.text_color, ); @@ -253,12 +253,23 @@ impl Renderer { view.theme.get("ui.statusline"), ); for i in (0..completion.len()) { - self.surface.set_string( - 1, - self.size.1 - 6 + i as u16, - &completion[i], - self.text_color, - ) + if prompt.completion_selection_index.is_some() + && i == prompt.completion_selection_index.unwrap() + { + self.surface.set_string( + 1, + self.size.1 - 6 + i as u16, + &completion[i], + Style::default().bg(Color::Rgb(104, 060, 232)), + ); + } else { + self.surface.set_string( + 1, + self.size.1 - 6 + i as u16, + &completion[i], + self.text_color, + ); + } } } // render buffer text @@ -409,16 +420,24 @@ impl Application { .. }] = keys.as_slice() { + let command_list = vec![ + String::from("q"), + String::from("aaa"), + String::from("bbb"), + String::from("ccc"), + ]; + let prompt = Prompt::new( ":".to_owned(), |_input: &str| { + let mut matches = vec![]; + // TODO: i need this duplicate list right now to avoid borrow checker issues let placeholder_list = vec![ String::from("q"), String::from("aaa"), String::from("bbb"), String::from("ccc"), ]; - let mut matches = vec![]; for command in placeholder_list { if command.contains(_input) { matches.push(command); @@ -433,6 +452,7 @@ impl Application { "q" => editor.should_close = true, _ => (), }, + command_list, ); self.prompt = Some(prompt); diff --git a/helix-view/src/prompt.rs b/helix-view/src/prompt.rs index 12f29942..032bbe54 100644 --- a/helix-view/src/prompt.rs +++ b/helix-view/src/prompt.rs @@ -8,6 +8,7 @@ pub struct Prompt { pub cursor: usize, pub completion: Option>, pub should_close: bool, + pub completion_selection_index: Option, completion_fn: Box Option>>, callback_fn: Box, } @@ -17,13 +18,15 @@ impl Prompt { prompt: String, 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: None, + completion: Some(command_list), should_close: false, + completion_selection_index: None, completion_fn: Box::new(completion_fn), callback_fn: Box::new(callback_fn), } @@ -32,6 +35,7 @@ impl Prompt { pub fn insert_char(&mut self, c: char) { self.line.insert(self.cursor, c); self.cursor += 1; + self.completion = (self.completion_fn)(&self.line); } pub fn move_char_left(&mut self) { @@ -58,6 +62,15 @@ impl Prompt { if self.cursor > 0 { self.line.remove(self.cursor - 1); self.cursor -= 1; + self.completion = (self.completion_fn)(&self.line); + } + } + + 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) } } @@ -96,9 +109,7 @@ impl Prompt { } => (self.callback_fn)(editor, &self.line), KeyEvent { code: KeyCode::Tab, .. - } => { - self.completion = (self.completion_fn)(&self.line); - } + } => self.change_completion_selection(), _ => (), } } -- cgit v1.2.3-70-g09d2 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-term/src/application.rs | 32 ++++++++------------------------ helix-view/src/prompt.rs | 20 ++++++++++++-------- 2 files changed, 20 insertions(+), 32 deletions(-) (limited to 'helix-term/src/application.rs') diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 75ebcb58..b2d1bb46 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -237,8 +237,7 @@ impl Renderer { pub fn render_prompt(&mut self, view: &View, prompt: &Prompt) { // completion - if prompt.completion.is_some() { - let completion = prompt.completion.clone().unwrap(); + if let Some(completion) = &prompt.completion { // TODO: find out better way of clearing individual lines of the screen for i in (3..7) { self.surface.set_string( @@ -253,23 +252,16 @@ impl Renderer { view.theme.get("ui.statusline"), ); for i in (0..completion.len()) { + let color; if prompt.completion_selection_index.is_some() && i == prompt.completion_selection_index.unwrap() { - self.surface.set_string( - 1, - self.size.1 - 6 + i as u16, - &completion[i], - Style::default().bg(Color::Rgb(104, 060, 232)), - ); + color = Style::default().bg(Color::Rgb(104, 060, 232)); } else { - self.surface.set_string( - 1, - self.size.1 - 6 + i as u16, - &completion[i], - self.text_color, - ); + color = self.text_color; } + self.surface + .set_string(1, self.size.1 - 6 + i as u16, &completion[i], color); } } // render buffer text @@ -420,25 +412,18 @@ impl Application { .. }] = keys.as_slice() { - let command_list = vec![ - String::from("q"), - String::from("aaa"), - String::from("bbb"), - String::from("ccc"), - ]; - let prompt = Prompt::new( ":".to_owned(), |_input: &str| { let mut matches = vec![]; // TODO: i need this duplicate list right now to avoid borrow checker issues - let placeholder_list = vec![ + let command_list = vec![ String::from("q"), String::from("aaa"), String::from("bbb"), String::from("ccc"), ]; - for command in placeholder_list { + for command in command_list { if command.contains(_input) { matches.push(command); } @@ -452,7 +437,6 @@ impl Application { "q" => editor.should_close = true, _ => (), }, - command_list, ); self.prompt = Some(prompt); 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 From 28a1e11fda09414bc1d9f39994c170a20cfd1b12 Mon Sep 17 00:00:00 2001 From: Jan Hrastnik Date: Fri, 30 Oct 2020 12:22:58 +0100 Subject: added more completions per line --- helix-term/src/application.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'helix-term/src/application.rs') diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index b2d1bb46..b48fafd8 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -251,17 +251,29 @@ impl Renderer { Rect::new(0, self.size.1 - 6, self.size.0, 4), view.theme.get("ui.statusline"), ); + let mut row = 0; + let mut col = 0; + // TODO: this will crash if there are too many cols added + // TODO: set char limit for i in (0..completion.len()) { - let color; - if prompt.completion_selection_index.is_some() + let color = if prompt.completion_selection_index.is_some() && i == prompt.completion_selection_index.unwrap() { - color = Style::default().bg(Color::Rgb(104, 060, 232)); + Style::default().bg(Color::Rgb(104, 060, 232)) } else { - color = self.text_color; + self.text_color + }; + self.surface.set_string( + 1 + col * 10, + self.size.1 - 6 + row as u16, + &completion[i], + color, + ); + row += 1; + if row > 3 { + row = 0; + col += 1; } - self.surface - .set_string(1, self.size.1 - 6 + i as u16, &completion[i], color); } } // render buffer text @@ -422,6 +434,8 @@ impl Application { String::from("aaa"), String::from("bbb"), String::from("ccc"), + String::from("ddd"), + String::from("eee"), ]; for command in command_list { if command.contains(_input) { -- cgit v1.2.3-70-g09d2 From c9e9fcf7c549fe98f5ac5f13cdee213da9c9ad7a Mon Sep 17 00:00:00 2001 From: Jan Hrastnik Date: Mon, 2 Nov 2020 10:41:27 +0100 Subject: added base col width --- helix-term/src/application.rs | 50 +++++++++++++++++++++++++++++++++++-------- helix-view/src/prompt.rs | 38 ++++++++++++++++---------------- 2 files changed, 61 insertions(+), 27 deletions(-) (limited to 'helix-term/src/application.rs') diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index b48fafd8..16e8a53d 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -34,6 +34,8 @@ type Terminal = tui::Terminal>; static EX: smol::Executor = smol::Executor::new(); +const BASE_WIDTH: u16 = 30; + pub struct Application { editor: Editor, prompt: Option, @@ -253,9 +255,10 @@ impl Renderer { ); let mut row = 0; let mut col = 0; + let max_row: u16 = self.size.0 / BASE_WIDTH; // TODO: this will crash if there are too many cols added // TODO: set char limit - for i in (0..completion.len()) { + for (i, command) in completion.iter().enumerate() { let color = if prompt.completion_selection_index.is_some() && i == prompt.completion_selection_index.unwrap() { @@ -263,16 +266,20 @@ impl Renderer { } else { self.text_color }; - self.surface.set_string( - 1 + col * 10, - self.size.1 - 6 + row as u16, - &completion[i], + self.surface.set_stringn( + 1 + row * BASE_WIDTH, + self.size.1 - 6 + col as u16, + &command, + BASE_WIDTH as usize - 1, color, ); - row += 1; - if row > 3 { - row = 0; - col += 1; + col += 1; + if col > 3 { + col = 0; + row += 1; + } + if row > max_row { + break; } } } @@ -436,6 +443,31 @@ impl Application { String::from("ccc"), String::from("ddd"), String::from("eee"), + String::from("averylongcommandaverylongcommandaverylongcommandaverylongcommandaverylongcommand"), + String::from("q"), + String::from("aaa"), + String::from("bbb"), + String::from("ccc"), + String::from("ddd"), + String::from("eee"), + String::from("q"), + String::from("aaa"), + String::from("bbb"), + String::from("ccc"), + String::from("ddd"), + String::from("eee"), + String::from("q"), + String::from("aaa"), + String::from("bbb"), + String::from("ccc"), + String::from("ddd"), + String::from("eee"), + String::from("q"), + String::from("aaa"), + String::from("bbb"), + String::from("ccc"), + String::from("ddd"), + String::from("eee"), ]; for command in command_list { if command.contains(_input) { diff --git a/helix-view/src/prompt.rs b/helix-view/src/prompt.rs index beb5e76d..749e54d2 100644 --- a/helix-view/src/prompt.rs +++ b/helix-view/src/prompt.rs @@ -39,7 +39,7 @@ impl Prompt { } pub fn move_char_left(&mut self) { - if self.cursor > 1 { + if self.cursor > 0 { self.cursor -= 1; } } @@ -68,23 +68,25 @@ impl Prompt { } pub fn change_completion_selection(&mut self) { - 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)); - self.line = String::from( - self.completion - .as_ref() - .unwrap() - .get(self.completion_selection_index.unwrap()) - .unwrap(), - ); + if self.completion.is_some() { + 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)); + self.line = String::from( + self.completion + .as_ref() + .unwrap() + .get(self.completion_selection_index.unwrap()) + .unwrap(), + ); + } } pub fn exit_selection(&mut self) { -- cgit v1.2.3-70-g09d2 From 2b44031929c490298cfc29cdd055ca4f22bf4645 Mon Sep 17 00:00:00 2001 From: Jan Hrastnik Date: Tue, 3 Nov 2020 10:57:12 +0100 Subject: various fixes --- helix-term/src/application.rs | 34 ++++++++++++++-------------------- helix-view/src/commands.rs | 4 ++++ helix-view/src/keymap.rs | 1 + helix-view/src/prompt.rs | 12 +++++------- 4 files changed, 24 insertions(+), 27 deletions(-) (limited to 'helix-term/src/application.rs') diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 16e8a53d..2c0b34dc 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -239,7 +239,7 @@ impl Renderer { pub fn render_prompt(&mut self, view: &View, prompt: &Prompt) { // completion - if let Some(completion) = &prompt.completion { + if !prompt.completion.is_empty() { // TODO: find out better way of clearing individual lines of the screen for i in (3..7) { self.surface.set_string( @@ -255,10 +255,10 @@ impl Renderer { ); let mut row = 0; let mut col = 0; - let max_row: u16 = self.size.0 / BASE_WIDTH; + let max_col: u16 = self.size.0 / BASE_WIDTH; // TODO: this will crash if there are too many cols added // TODO: set char limit - for (i, command) in completion.iter().enumerate() { + for (i, command) in prompt.completion.iter().enumerate() { let color = if prompt.completion_selection_index.is_some() && i == prompt.completion_selection_index.unwrap() { @@ -267,18 +267,18 @@ impl Renderer { self.text_color }; self.surface.set_stringn( - 1 + row * BASE_WIDTH, - self.size.1 - 6 + col as u16, + 1 + col * BASE_WIDTH, + self.size.1 - 6 + row as u16, &command, BASE_WIDTH as usize - 1, color, ); - col += 1; - if col > 3 { - col = 0; - row += 1; + row += 1; + if row > 3 { + row = 0; + col += 1; } - if row > max_row { + if col > max_col { break; } } @@ -434,7 +434,6 @@ impl Application { let prompt = Prompt::new( ":".to_owned(), |_input: &str| { - let mut matches = vec![]; // TODO: i need this duplicate list right now to avoid borrow checker issues let command_list = vec![ String::from("q"), @@ -469,15 +468,10 @@ impl Application { String::from("ddd"), String::from("eee"), ]; - for command in command_list { - if command.contains(_input) { - matches.push(command); - } - } - if matches.len() != 0 { - return Some(matches); - } - None + command_list + .into_iter() + .filter(|command| command.contains(_input)) + .collect() }, // completion |editor: &mut Editor, input: &str| match input { "q" => editor.should_close = true, diff --git a/helix-view/src/commands.rs b/helix-view/src/commands.rs index 905f4e10..1d7737f0 100644 --- a/helix-view/src/commands.rs +++ b/helix-view/src/commands.rs @@ -309,6 +309,10 @@ pub fn append_mode(view: &mut View, _count: usize) { // TODO: I, A, o and O can share a lot of the primitives. +pub fn command_mode(_view: &mut View, _count: usize) { + unimplemented!() +} + // calculate line numbers for each selection range fn selection_lines(state: &State) -> Vec { let mut lines = state diff --git a/helix-view/src/keymap.rs b/helix-view/src/keymap.rs index f70b9deb..69e6cabb 100644 --- a/helix-view/src/keymap.rs +++ b/helix-view/src/keymap.rs @@ -163,6 +163,7 @@ pub fn default() -> Keymaps { vec![key!('p')] => commands::paste, vec![key!('>')] => commands::indent, vec![key!('<')] => commands::unindent, + vec![key!(':')] => commands::command_mode, vec![Key { code: KeyCode::Esc, modifiers: Modifiers::NONE diff --git a/helix-view/src/prompt.rs b/helix-view/src/prompt.rs index 749e54d2..8186b476 100644 --- a/helix-view/src/prompt.rs +++ b/helix-view/src/prompt.rs @@ -6,17 +6,17 @@ pub struct Prompt { pub prompt: String, pub line: String, pub cursor: usize, - pub completion: Option>, + pub completion: Vec, pub should_close: bool, pub completion_selection_index: Option, - completion_fn: Box Option>>, + completion_fn: Box Vec>, callback_fn: Box, } impl Prompt { pub fn new( prompt: String, - mut completion_fn: impl FnMut(&str) -> Option> + 'static, + mut completion_fn: impl FnMut(&str) -> Vec + 'static, callback_fn: impl FnMut(&mut Editor, &str) + 'static, ) -> Prompt { Prompt { @@ -68,11 +68,11 @@ impl Prompt { } pub fn change_completion_selection(&mut self) { - if self.completion.is_some() { + if !self.completion.is_empty() { self.completion_selection_index = self .completion_selection_index .map(|i| { - if i == self.completion.as_ref().unwrap().len() - 1 { + if i == self.completion.len() - 1 { 0 } else { i + 1 @@ -81,8 +81,6 @@ impl Prompt { .or(Some(0)); self.line = String::from( self.completion - .as_ref() - .unwrap() .get(self.completion_selection_index.unwrap()) .unwrap(), ); -- cgit v1.2.3-70-g09d2 From 1a3c647adf1f252478bf38537bde87f7e5f14ab0 Mon Sep 17 00:00:00 2001 From: Jan Hrastnik Date: Fri, 13 Nov 2020 00:07:21 +0100 Subject: added col_height calculation --- helix-term/src/application.rs | 18 +++++++++--------- helix-view/src/prompt.rs | 23 ++++++----------------- 2 files changed, 15 insertions(+), 26 deletions(-) (limited to 'helix-term/src/application.rs') diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 2c0b34dc..1e719f5f 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -241,7 +241,12 @@ impl Renderer { // completion if !prompt.completion.is_empty() { // TODO: find out better way of clearing individual lines of the screen - for i in (3..7) { + let mut row = 0; + let mut col = 0; + let max_col = self.size.0 / BASE_WIDTH; + let col_height = ((prompt.completion.len() as u16 + max_col - 1) / max_col); + + for i in (3..col_height + 3) { self.surface.set_string( 0, self.size.1 - i as u16, @@ -250,14 +255,9 @@ impl Renderer { ); } self.surface.set_style( - Rect::new(0, self.size.1 - 6, self.size.0, 4), + Rect::new(0, self.size.1 - col_height - 2, self.size.0, col_height), view.theme.get("ui.statusline"), ); - let mut row = 0; - let mut col = 0; - let max_col: u16 = self.size.0 / BASE_WIDTH; - // TODO: this will crash if there are too many cols added - // TODO: set char limit for (i, command) in prompt.completion.iter().enumerate() { let color = if prompt.completion_selection_index.is_some() && i == prompt.completion_selection_index.unwrap() @@ -268,13 +268,13 @@ impl Renderer { }; self.surface.set_stringn( 1 + col * BASE_WIDTH, - self.size.1 - 6 + row as u16, + self.size.1 - col_height - 2 + row, &command, BASE_WIDTH as usize - 1, color, ); row += 1; - if row > 3 { + if row > col_height - 1 { row = 0; col += 1; } diff --git a/helix-view/src/prompt.rs b/helix-view/src/prompt.rs index 8186b476..e2a9c80d 100644 --- a/helix-view/src/prompt.rs +++ b/helix-view/src/prompt.rs @@ -68,25 +68,14 @@ impl Prompt { } pub fn change_completion_selection(&mut self) { - if !self.completion.is_empty() { - self.completion_selection_index = self - .completion_selection_index - .map(|i| { - if i == self.completion.len() - 1 { - 0 - } else { - i + 1 - } - }) - .or(Some(0)); - self.line = String::from( - self.completion - .get(self.completion_selection_index.unwrap()) - .unwrap(), - ); + if self.completion.is_empty() { + return; } + let index = + self.completion_selection_index.map(|i| i + 1).unwrap_or(0) % self.completion.len(); + self.completion_selection_index = Some(index); + self.line = self.completion[index].clone(); } - pub fn exit_selection(&mut self) { self.completion_selection_index = None; } -- cgit v1.2.3-70-g09d2