on master help sign in
completion is now added to prompt.line
956173bJan Hrastnik
helix-view/src/prompt.rs+19−2
@@ -35,6 +35,7 @@ impl Prompt {
35 self.line.insert(self.cursor, c);
35 self.line.insert(self.cursor, c);
36 self.cursor += 1;
36 self.cursor += 1;
37 self.completion = (self.completion_fn)(&self.line);
37 self.completion = (self.completion_fn)(&self.line);
38+ self.exit_selection();
38 }
39 }
39
40
40 pub fn move_char_left(&mut self) {
41 pub fn move_char_left(&mut self) {
@@ -63,6 +64,7 @@ impl Prompt {
63 self.cursor -= 1;
64 self.cursor -= 1;
64 self.completion = (self.completion_fn)(&self.line);
65 self.completion = (self.completion_fn)(&self.line);
65 }
66 }
67+ self.exit_selection();
66 }
68 }
67
69
68 pub fn change_completion_selection(&mut self) {
70 pub fn change_completion_selection(&mut self) {
@@ -75,7 +77,18 @@ impl Prompt {
75 i + 1
77 i + 1
76 }
78 }
77 })
79 })
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;
79 }
92 }
80
93
81 pub fn handle_input(&mut self, key_event: KeyEvent, editor: &mut Editor) {
94 pub fn handle_input(&mut self, key_event: KeyEvent, editor: &mut Editor) {
@@ -105,7 +118,7 @@ impl Prompt {
105 } => self.move_start(),
118 } => self.move_start(),
106 KeyEvent {
119 KeyEvent {
107 code: KeyCode::Backspace,
120 code: KeyCode::Backspace,
108− ..
121+ modifiers: KeyModifiers::NONE,
109 } => self.delete_char_backwards(),
122 } => self.delete_char_backwards(),
110 KeyEvent {
123 KeyEvent {
111 code: KeyCode::Enter,
124 code: KeyCode::Enter,
@@ -114,6 +127,10 @@ impl Prompt {
114 KeyEvent {
127 KeyEvent {
115 code: KeyCode::Tab, ..
128 code: KeyCode::Tab, ..
116 } => self.change_completion_selection(),
129 } => self.change_completion_selection(),
130+ KeyEvent {
131+ code: KeyCode::Char('q'),
132+ modifiers: KeyModifiers::CONTROL,
133+ } => self.exit_selection(),
117 _ => (),
134 _ => (),
118 }
135 }
119 }
136 }