on master help sign in
completion is now added to prompt.line
commit956173bceae9c1575b42b0edf1cd04f9fa106490 authorJan Hrastnik <jan.hrastnik2@gmail.com> dateSat 24 Oct 2020, 14:06 (6 years ago) parenta123cf3
1 file changed+19−2
helix-view/src/prompt.rs+19−2
helix-view/src/prompt.rs+19−2
@@ -35,6 +35,7 @@ impl Prompt {
3535 self.line.insert(self.cursor, c);
3636 self.cursor += 1;
3737 self.completion = (self.completion_fn)(&self.line);
38+ self.exit_selection();
3839 }
3940
4041 pub fn move_char_left(&mut self) {
@@ -63,6 +64,7 @@ impl Prompt {
6364 self.cursor -= 1;
6465 self.completion = (self.completion_fn)(&self.line);
6566 }
67+ self.exit_selection();
6668 }
6769
6870 pub fn change_completion_selection(&mut self) {
@@ -75,7 +77,18 @@ impl Prompt {
7577 i + 1
7678 }
7779 })
78− .or(Some(0))
80+ .or(Some(0));
81+ self.line = String::from(
82+ self.completion
83+ .as_ref()
84+ .unwrap()
85+ .get(self.completion_selection_index.unwrap())
86+ .unwrap(),
87+ );
88+ }
89+
90+ pub fn exit_selection(&mut self) {
91+ self.completion_selection_index = None;
7992 }
8093
8194 pub fn handle_input(&mut self, key_event: KeyEvent, editor: &mut Editor) {
@@ -105,7 +118,7 @@ impl Prompt {
105118 } => self.move_start(),
106119 KeyEvent {
107120 code: KeyCode::Backspace,
108− ..
121+ modifiers: KeyModifiers::NONE,
109122 } => self.delete_char_backwards(),
110123 KeyEvent {
111124 code: KeyCode::Enter,
@@ -114,6 +127,10 @@ impl Prompt {
114127 KeyEvent {
115128 code: KeyCode::Tab, ..
116129 } => self.change_completion_selection(),
130+ KeyEvent {
131+ code: KeyCode::Char('q'),
132+ modifiers: KeyModifiers::CONTROL,
133+ } => self.exit_selection(),
117134 _ => (),
118135 }
119136 }