From 182a59b5528075c0171756bff71275db8a7995f0 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Fri, 22 Oct 2021 12:07:41 +0900 Subject: Update to rust 1.56 + 2021 edition --- helix-term/src/ui/menu.rs | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'helix-term/src/ui/menu.rs') diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs index 055593fd..1130089d 100644 --- a/helix-term/src/ui/menu.rs +++ b/helix-term/src/ui/menu.rs @@ -64,25 +64,23 @@ impl Menu { } pub fn score(&mut self, pattern: &str) { - // need to borrow via pattern match otherwise it complains about simultaneous borrow - let Self { - ref mut matcher, - ref mut matches, - ref options, - .. - } = *self; - // reuse the matches allocation - matches.clear(); - matches.extend(options.iter().enumerate().filter_map(|(index, option)| { - let text = option.filter_text(); - // TODO: using fuzzy_indices could give us the char idx for match highlighting - matcher - .fuzzy_match(text, pattern) - .map(|score| (index, score)) - })); + self.matches.clear(); + self.matches.extend( + self.options + .iter() + .enumerate() + .filter_map(|(index, option)| { + let text = option.filter_text(); + // TODO: using fuzzy_indices could give us the char idx for match highlighting + self.matcher + .fuzzy_match(text, pattern) + .map(|score| (index, score)) + }), + ); // matches.sort_unstable_by_key(|(_, score)| -score); - matches.sort_unstable_by_key(|(index, _score)| options[*index].sort_text()); + self.matches + .sort_unstable_by_key(|(index, _score)| self.options[*index].sort_text()); // reset cursor position self.cursor = None; -- cgit v1.2.3-70-g09d2 From bca98b5bedfa6c9410384f26a2df6115874351bc Mon Sep 17 00:00:00 2001 From: CossonLeo Date: Tue, 26 Oct 2021 08:42:08 +0800 Subject: Add c-j c-k to menu keymap for move_up move_down (#908) --- helix-term/src/ui/menu.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'helix-term/src/ui/menu.rs') diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs index 1130089d..dd163d34 100644 --- a/helix-term/src/ui/menu.rs +++ b/helix-term/src/ui/menu.rs @@ -214,6 +214,10 @@ impl Component for Menu { | KeyEvent { code: KeyCode::Char('p'), modifiers: KeyModifiers::CONTROL, + } + | KeyEvent { + code: KeyCode::Char('k'), + modifiers: KeyModifiers::CONTROL, } => { self.move_up(); (self.callback_fn)(cx.editor, self.selection(), MenuEvent::Update); @@ -231,6 +235,10 @@ impl Component for Menu { | KeyEvent { code: KeyCode::Char('n'), modifiers: KeyModifiers::CONTROL, + } + | KeyEvent { + code: KeyCode::Char('j'), + modifiers: KeyModifiers::CONTROL, } => { self.move_down(); (self.callback_fn)(cx.editor, self.selection(), MenuEvent::Update); -- cgit v1.2.3-70-g09d2 From b142fd4080d99a7e4f39bb06207ded6771d47b20 Mon Sep 17 00:00:00 2001 From: CossonLeo Date: Tue, 26 Oct 2021 08:42:23 +0800 Subject: move_up will select last item, when no item selected (#907) --- helix-term/src/ui/menu.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'helix-term/src/ui/menu.rs') diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs index dd163d34..3c492d14 100644 --- a/helix-term/src/ui/menu.rs +++ b/helix-term/src/ui/menu.rs @@ -98,7 +98,8 @@ impl Menu { pub fn move_up(&mut self) { let len = self.matches.len(); - let pos = self.cursor.map_or(0, |i| (i + len.saturating_sub(1)) % len) % len; + let max_index = len.saturating_sub(1); + let pos = self.cursor.map_or(max_index, |i| (i + max_index) % len) % len; self.cursor = Some(pos); self.adjust_scroll(); } -- cgit v1.2.3-70-g09d2