on master help sign in
several fixes
a123cf3Jan Hrastnik
helix-term/src/application.rs+8−24
@@ -237,8 +237,7 @@ impl Renderer {
237
237
238 pub fn render_prompt(&mut self, view: &View, prompt: &Prompt) {
238 pub fn render_prompt(&mut self, view: &View, prompt: &Prompt) {
239 // completion
239 // completion
240− if prompt.completion.is_some() {
241− let completion = prompt.completion.clone().unwrap();
240+ if let Some(completion) = &prompt.completion {
242 // TODO: find out better way of clearing individual lines of the screen
241 // TODO: find out better way of clearing individual lines of the screen
243 for i in (3..7) {
242 for i in (3..7) {
244 self.surface.set_string(
243 self.surface.set_string(
@@ -253,23 +252,16 @@ impl Renderer {
253 view.theme.get("ui.statusline"),
252 view.theme.get("ui.statusline"),
254 );
253 );
255 for i in (0..completion.len()) {
254 for i in (0..completion.len()) {
255+ let color;
256 if prompt.completion_selection_index.is_some()
256 if prompt.completion_selection_index.is_some()
257 && i == prompt.completion_selection_index.unwrap()
257 && i == prompt.completion_selection_index.unwrap()
258 {
258 {
259− self.surface.set_string(
260− 1,
261− self.size.1 - 6 + i as u16,
262− &completion[i],
263− Style::default().bg(Color::Rgb(104, 060, 232)),
259+ color = Style::default().bg(Color::Rgb(104, 060, 232));
264− );
265 } else {
260 } else {
266− self.surface.set_string(
267− 1,
268− self.size.1 - 6 + i as u16,
269− &completion[i],
270− self.text_color,
261+ color = self.text_color;
271− );
272 }
262 }
263+ self.surface
264+ .set_string(1, self.size.1 - 6 + i as u16, &completion[i], color);
273 }
265 }
274 }
266 }
275 // render buffer text
267 // render buffer text
@@ -420,25 +412,18 @@ impl Application {
420 ..
412 ..
421 }] = keys.as_slice()
413 }] = keys.as_slice()
422 {
414 {
423− let command_list = vec![
424− String::from("q"),
425− String::from("aaa"),
426− String::from("bbb"),
427− String::from("ccc"),
428− ];
429−
430 let prompt = Prompt::new(
415 let prompt = Prompt::new(
431 ":".to_owned(),
416 ":".to_owned(),
432 |_input: &str| {
417 |_input: &str| {
433 let mut matches = vec![];
418 let mut matches = vec![];
434 // TODO: i need this duplicate list right now to avoid borrow checker issues
419 // TODO: i need this duplicate list right now to avoid borrow checker issues
435− let placeholder_list = vec![
420+ let command_list = vec![
436 String::from("q"),
421 String::from("q"),
437 String::from("aaa"),
422 String::from("aaa"),
438 String::from("bbb"),
423 String::from("bbb"),
439 String::from("ccc"),
424 String::from("ccc"),
440 ];
425 ];
441− for command in placeholder_list {
426+ for command in command_list {
442 if command.contains(_input) {
427 if command.contains(_input) {
443 matches.push(command);
428 matches.push(command);
444 }
429 }
@@ -452,7 +437,6 @@ impl Application {
452 "q" => editor.should_close = true,
437 "q" => editor.should_close = true,
453 _ => (),
438 _ => (),
454 },
439 },
455− command_list,
456 );
440 );
457
441
458 self.prompt = Some(prompt);
442 self.prompt = Some(prompt);
helix-view/src/prompt.rs+12−8
@@ -16,15 +16,14 @@ pub struct Prompt {
16impl Prompt {
16impl Prompt {
17 pub fn new(
17 pub fn new(
18 prompt: String,
18 prompt: String,
19− completion_fn: impl FnMut(&str) -> Option<Vec<String>> + 'static,
19+ mut completion_fn: impl FnMut(&str) -> Option<Vec<String>> + 'static,
20 callback_fn: impl FnMut(&mut Editor, &str) + 'static,
20 callback_fn: impl FnMut(&mut Editor, &str) + 'static,
21− command_list: Vec<String>,
22 ) -> Prompt {
21 ) -> Prompt {
23 Prompt {
22 Prompt {
24 prompt,
23 prompt,
25 line: String::new(),
24 line: String::new(),
26 cursor: 0,
25 cursor: 0,
27− completion: Some(command_list),
26+ completion: completion_fn(""),
28 should_close: false,
27 should_close: false,
29 completion_selection_index: None,
28 completion_selection_index: None,
30 completion_fn: Box::new(completion_fn),
29 completion_fn: Box::new(completion_fn),
@@ -67,11 +66,16 @@ impl Prompt {
67 }
66 }
68
67
69 pub fn change_completion_selection(&mut self) {
68 pub fn change_completion_selection(&mut self) {
70− if self.completion_selection_index.is_none() {
69+ self.completion_selection_index = self
71− self.completion_selection_index = Some(0)
70+ .completion_selection_index
72− } else {
71+ .map(|i| {
73− self.completion_selection_index = Some(self.completion_selection_index.unwrap() + 1)
72+ if i == self.completion.as_ref().unwrap().len() - 1 {
73+ 0
74+ } else {
75+ i + 1
74− }
76+ }
77+ })
78+ .or(Some(0))
75 }
79 }
76
80
77 pub fn handle_input(&mut self, key_event: KeyEvent, editor: &mut Editor) {
81 pub fn handle_input(&mut self, key_event: KeyEvent, editor: &mut Editor) {