@@ -11,7 +11,7 @@ use helix_view::{graphics::Rect, Editor};
11use tui::layout::Constraint;
11use tui::layout::Constraint;
13pub trait Item {
13pub trait Item {
14− // TODO: sort_text
14+ fn sort_text(&self) -> &str;
15 fn filter_text(&self) -> &str;
15 fn filter_text(&self) -> &str;
17 fn label(&self) -> &str;
17 fn label(&self) -> &str;
@@ -64,24 +64,21 @@ impl<T: Item> Menu<T> {
64 let Self {
64 let Self {
65 ref mut matcher,
65 ref mut matcher,
66 ref mut matches,
66 ref mut matches,
68 } = *self;
69 } = *self;
70 // reuse the matches allocation
71 // reuse the matches allocation
71 matches.clear();
72 matches.clear();
76− .filter_map(|(index, option)| {
73+ matches.extend(options.iter().enumerate().filter_map(|(index, option)| {
77− let text = option.filter_text();
74+ let text = option.filter_text();
78− // TODO: using fuzzy_indices could give us the char idx for match highlighting
75+ // TODO: using fuzzy_indices could give us the char idx for match highlighting
80− .fuzzy_match(text, pattern)
77+ .fuzzy_match(text, pattern)
81− .map(|score| (index, score))
78+ .map(|score| (index, score))
84− matches.sort_unstable_by_key(|(_, score)| -score);
80+ // matches.sort_unstable_by_key(|(_, score)| -score);
81+ matches.sort_unstable_by_key(|(index, _score)| options[*index].sort_text());
86 // reset cursor position
83 // reset cursor position
87 self.cursor = None;
84 self.cursor = None;
@@ -223,8 +220,6 @@ impl<T: Item + 'static> Component for Menu<T> {
223 EventResult::Ignored
220 EventResult::Ignored
226− // TODO: completion sorting
228 fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
223 fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
229 let n = self
224 let n = self