From 189aa0bfcfb6841ced946289e112cc9cdd4919a5 Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Thu, 13 Oct 2022 20:10:10 +0200 Subject: never sort menu items when no fuzzy matching is possible --- helix-term/src/ui/completion.rs | 2 +- helix-term/src/ui/menu.rs | 15 +++------------ 2 files changed, 4 insertions(+), 13 deletions(-) (limited to 'helix-term/src/ui') diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index 2e555e4b..7348dcf4 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -97,7 +97,7 @@ impl Completion { start_offset: usize, trigger_offset: usize, ) -> Self { - let menu = Menu::new(items, true, (), move |editor: &mut Editor, item, event| { + let menu = Menu::new(items, (), move |editor: &mut Editor, item, event| { fn item_to_transaction( doc: &Document, item: &CompletionItem, diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs index f7712e4d..4b1155e3 100644 --- a/helix-term/src/ui/menu.rs +++ b/helix-term/src/ui/menu.rs @@ -74,15 +74,15 @@ impl Menu { // rendering) pub fn new( options: Vec, - sort: bool, editor_data: ::Data, callback_fn: impl Fn(&mut Editor, Option<&T>, MenuEvent) + 'static, ) -> Self { - let mut menu = Self { + let matches = (0..options.len()).map(|i| (i, 0)).collect(); + Self { options, editor_data, matcher: Box::new(Matcher::default()), - matches: Vec::new(), + matches, cursor: None, widths: Vec::new(), callback_fn: Box::new(callback_fn), @@ -90,16 +90,7 @@ impl Menu { size: (0, 0), viewport: (0, 0), recalculate: true, - }; - - if sort { - // TODO: scoring on empty input should just use a fastpath - menu.score(""); - } else { - menu.matches = (0..menu.options.len()).map(|i| (i, 0)).collect(); } - - menu } pub fn score(&mut self, pattern: &str) { -- cgit v1.2.3-70-g09d2