on master help sign in
various fixes
commit2b44031929c490298cfc29cdd055ca4f22bf4645 authorJan Hrastnik <jan.hrastnik2@gmail.com> dateTue 3 Nov 2020, 10:57 (6 years ago) parentc9e9fcf
4 files changed+24−27
helix-term/src/application.rs+14−20 helix-view/src/commands.rs+4 helix-view/src/keymap.rs+1 helix-view/src/prompt.rs+5−7
helix-term/src/application.rs+14−20
@@ -239,7 +239,7 @@ impl Renderer {
239239
240240 pub fn render_prompt(&mut self, view: &View, prompt: &Prompt) {
241241 // completion
242− if let Some(completion) = &prompt.completion {
242+ if !prompt.completion.is_empty() {
243243 // TODO: find out better way of clearing individual lines of the screen
244244 for i in (3..7) {
245245 self.surface.set_string(
@@ -255,10 +255,10 @@ impl Renderer {
255255 );
256256 let mut row = 0;
257257 let mut col = 0;
258− let max_row: u16 = self.size.0 / BASE_WIDTH;
258+ let max_col: u16 = self.size.0 / BASE_WIDTH;
259259 // TODO: this will crash if there are too many cols added
260260 // TODO: set char limit
261− for (i, command) in completion.iter().enumerate() {
261+ for (i, command) in prompt.completion.iter().enumerate() {
262262 let color = if prompt.completion_selection_index.is_some()
263263 && i == prompt.completion_selection_index.unwrap()
264264 {
@@ -267,18 +267,18 @@ impl Renderer {
267267 self.text_color
268268 };
269269 self.surface.set_stringn(
270− 1 + row * BASE_WIDTH,
271− self.size.1 - 6 + col as u16,
270+ 1 + col * BASE_WIDTH,
271+ self.size.1 - 6 + row as u16,
272272 &command,
273273 BASE_WIDTH as usize - 1,
274274 color,
275275 );
276− col += 1;
277− if col > 3 {
278− col = 0;
279− row += 1;
276+ row += 1;
277+ if row > 3 {
278+ row = 0;
279+ col += 1;
280280 }
281− if row > max_row {
281+ if col > max_col {
282282 break;
283283 }
284284 }
@@ -434,7 +434,6 @@ impl Application {
434434 let prompt = Prompt::new(
435435 ":".to_owned(),
436436 |_input: &str| {
437− let mut matches = vec![];
438437 // TODO: i need this duplicate list right now to avoid borrow checker issues
439438 let command_list = vec![
440439 String::from("q"),
@@ -469,15 +468,10 @@ impl Application {
469468 String::from("ddd"),
470469 String::from("eee"),
471470 ];
472− for command in command_list {
473− if command.contains(_input) {
474− matches.push(command);
475− }
476− }
477− if matches.len() != 0 {
478− return Some(matches);
479− }
480− None
471+ command_list
472+ .into_iter()
473+ .filter(|command| command.contains(_input))
474+ .collect()
481475 }, // completion
482476 |editor: &mut Editor, input: &str| match input {
483477 "q" => editor.should_close = true,
helix-view/src/commands.rs+4
@@ -309,6 +309,10 @@ pub fn append_mode(view: &mut View, _count: usize) {
309309
310310// TODO: I, A, o and O can share a lot of the primitives.
311311
312+pub fn command_mode(_view: &mut View, _count: usize) {
313+ unimplemented!()
314+}
315+
312316// calculate line numbers for each selection range
313317fn selection_lines(state: &State) -> Vec<usize> {
314318 let mut lines = state
helix-view/src/keymap.rs+1
@@ -163,6 +163,7 @@ pub fn default() -> Keymaps {
163163 vec![key!('p')] => commands::paste,
164164 vec![key!('>')] => commands::indent,
165165 vec![key!('<')] => commands::unindent,
166+ vec![key!(':')] => commands::command_mode,
166167 vec![Key {
167168 code: KeyCode::Esc,
168169 modifiers: Modifiers::NONE
helix-view/src/prompt.rs+5−7
@@ -6,17 +6,17 @@ pub struct Prompt {
66 pub prompt: String,
77 pub line: String,
88 pub cursor: usize,
9− pub completion: Option<Vec<String>>,
9+ pub completion: Vec<String>,
1010 pub should_close: bool,
1111 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>>,
1313 callback_fn: Box<dyn FnMut(&mut Editor, &str)>,
1414}
1515
1616impl Prompt {
1717 pub fn new(
1818 prompt: String,
19− mut completion_fn: impl FnMut(&str) -> Option<Vec<String>> + 'static,
19+ mut completion_fn: impl FnMut(&str) -> Vec<String> + 'static,
2020 callback_fn: impl FnMut(&mut Editor, &str) + 'static,
2121 ) -> Prompt {
2222 Prompt {
@@ -68,11 +68,11 @@ impl Prompt {
6868 }
6969
7070 pub fn change_completion_selection(&mut self) {
71− if self.completion.is_some() {
71+ if !self.completion.is_empty() {
7272 self.completion_selection_index = self
7373 .completion_selection_index
7474 .map(|i| {
75− if i == self.completion.as_ref().unwrap().len() - 1 {
75+ if i == self.completion.len() - 1 {
7676 0
7777 } else {
7878 i + 1
@@ -81,8 +81,6 @@ impl Prompt {
8181 .or(Some(0));
8282 self.line = String::from(
8383 self.completion
84− .as_ref()
85− .unwrap()
8684 .get(self.completion_selection_index.unwrap())
8785 .unwrap(),
8886 );