on master help sign in
various fixes
2b44031Jan Hrastnik
helix-term/src/application.rs+14−20
@@ -239,7 +239,7 @@ impl Renderer {
239
239
240 pub fn render_prompt(&mut self, view: &View, prompt: &Prompt) {
240 pub fn render_prompt(&mut self, view: &View, prompt: &Prompt) {
241 // completion
241 // completion
242− if let Some(completion) = &prompt.completion {
242+ if !prompt.completion.is_empty() {
243 // TODO: find out better way of clearing individual lines of the screen
243 // TODO: find out better way of clearing individual lines of the screen
244 for i in (3..7) {
244 for i in (3..7) {
245 self.surface.set_string(
245 self.surface.set_string(
@@ -255,10 +255,10 @@ impl Renderer {
255 );
255 );
256 let mut row = 0;
256 let mut row = 0;
257 let mut col = 0;
257 let mut col = 0;
258− let max_row: u16 = self.size.0 / BASE_WIDTH;
258+ let max_col: u16 = self.size.0 / BASE_WIDTH;
259 // TODO: this will crash if there are too many cols added
259 // TODO: this will crash if there are too many cols added
260 // TODO: set char limit
260 // TODO: set char limit
261− for (i, command) in completion.iter().enumerate() {
261+ for (i, command) in prompt.completion.iter().enumerate() {
262 let color = if prompt.completion_selection_index.is_some()
262 let color = if prompt.completion_selection_index.is_some()
263 && i == prompt.completion_selection_index.unwrap()
263 && i == prompt.completion_selection_index.unwrap()
264 {
264 {
@@ -267,18 +267,18 @@ impl Renderer {
267 self.text_color
267 self.text_color
268 };
268 };
269 self.surface.set_stringn(
269 self.surface.set_stringn(
270− 1 + row * BASE_WIDTH,
270+ 1 + col * BASE_WIDTH,
271− self.size.1 - 6 + col as u16,
271+ self.size.1 - 6 + row as u16,
272 &command,
272 &command,
273 BASE_WIDTH as usize - 1,
273 BASE_WIDTH as usize - 1,
274 color,
274 color,
275 );
275 );
276− col += 1;
276+ row += 1;
277− if col > 3 {
277+ if row > 3 {
278− col = 0;
278+ row = 0;
279− row += 1;
279+ col += 1;
280 }
280 }
281− if row > max_row {
281+ if col > max_col {
282 break;
282 break;
283 }
283 }
284 }
284 }
@@ -434,7 +434,6 @@ impl Application {
434 let prompt = Prompt::new(
434 let prompt = Prompt::new(
435 ":".to_owned(),
435 ":".to_owned(),
436 |_input: &str| {
436 |_input: &str| {
437− let mut matches = vec![];
438 // TODO: i need this duplicate list right now to avoid borrow checker issues
437 // TODO: i need this duplicate list right now to avoid borrow checker issues
439 let command_list = vec![
438 let command_list = vec![
440 String::from("q"),
439 String::from("q"),
@@ -469,15 +468,10 @@ impl Application {
469 String::from("ddd"),
468 String::from("ddd"),
470 String::from("eee"),
469 String::from("eee"),
471 ];
470 ];
472− for command in command_list {
471+ command_list
472+ .into_iter()
473− if command.contains(_input) {
473+ .filter(|command| command.contains(_input))
474− matches.push(command);
474+ .collect()
475− }
476− }
477− if matches.len() != 0 {
478− return Some(matches);
479− }
480− None
481 }, // completion
475 }, // completion
482 |editor: &mut Editor, input: &str| match input {
476 |editor: &mut Editor, input: &str| match input {
483 "q" => editor.should_close = true,
477 "q" => editor.should_close = true,
helix-view/src/commands.rs+4
@@ -309,6 +309,10 @@ pub fn append_mode(view: &mut View, _count: usize) {
309
309
310// TODO: I, A, o and O can share a lot of the primitives.
310// TODO: I, A, o and O can share a lot of the primitives.
311
311
312+pub fn command_mode(_view: &mut View, _count: usize) {
313+ unimplemented!()
314+}
315+
312// calculate line numbers for each selection range
316// calculate line numbers for each selection range
313fn selection_lines(state: &State) -> Vec<usize> {
317fn selection_lines(state: &State) -> Vec<usize> {
314 let mut lines = state
318 let mut lines = state
helix-view/src/keymap.rs+1
@@ -163,6 +163,7 @@ pub fn default() -> Keymaps {
163 vec![key!('p')] => commands::paste,
163 vec![key!('p')] => commands::paste,
164 vec![key!('>')] => commands::indent,
164 vec![key!('>')] => commands::indent,
165 vec![key!('<')] => commands::unindent,
165 vec![key!('<')] => commands::unindent,
166+ vec![key!(':')] => commands::command_mode,
166 vec![Key {
167 vec![Key {
167 code: KeyCode::Esc,
168 code: KeyCode::Esc,
168 modifiers: Modifiers::NONE
169 modifiers: Modifiers::NONE
helix-view/src/prompt.rs+5−7
@@ -6,17 +6,17 @@ pub struct Prompt {
6 pub prompt: String,
6 pub prompt: String,
7 pub line: String,
7 pub line: String,
8 pub cursor: usize,
8 pub cursor: usize,
9− pub completion: Option<Vec<String>>,
9+ pub completion: Vec<String>,
10 pub should_close: bool,
10 pub should_close: bool,
11 pub completion_selection_index: Option<usize>,
11 pub completion_selection_index: Option<usize>,
12− completion_fn: Box<dyn FnMut(&str) -> Option<Vec<String>>>,
12+ completion_fn: Box<dyn FnMut(&str) -> Vec<String>>,
13 callback_fn: Box<dyn FnMut(&mut Editor, &str)>,
13 callback_fn: Box<dyn FnMut(&mut Editor, &str)>,
14}
14}
15
15
16impl Prompt {
16impl Prompt {
17 pub fn new(
17 pub fn new(
18 prompt: String,
18 prompt: String,
19− mut completion_fn: impl FnMut(&str) -> Option<Vec<String>> + 'static,
19+ mut completion_fn: impl FnMut(&str) -> Vec<String> + 'static,
20 callback_fn: impl FnMut(&mut Editor, &str) + 'static,
20 callback_fn: impl FnMut(&mut Editor, &str) + 'static,
21 ) -> Prompt {
21 ) -> Prompt {
22 Prompt {
22 Prompt {
@@ -68,11 +68,11 @@ impl Prompt {
68 }
68 }
69
69
70 pub fn change_completion_selection(&mut self) {
70 pub fn change_completion_selection(&mut self) {
71− if self.completion.is_some() {
71+ if !self.completion.is_empty() {
72 self.completion_selection_index = self
72 self.completion_selection_index = self
73 .completion_selection_index
73 .completion_selection_index
74 .map(|i| {
74 .map(|i| {
75− if i == self.completion.as_ref().unwrap().len() - 1 {
75+ if i == self.completion.len() - 1 {
76 0
76 0
77 } else {
77 } else {
78 i + 1
78 i + 1
@@ -81,8 +81,6 @@ impl Prompt {
81 .or(Some(0));
81 .or(Some(0));
82 self.line = String::from(
82 self.line = String::from(
83 self.completion
83 self.completion
84− .as_ref()
85− .unwrap()
86 .get(self.completion_selection_index.unwrap())
84 .get(self.completion_selection_index.unwrap())
87 .unwrap(),
85 .unwrap(),
88 );
86 );