@@ -11,7 +11,7 @@ use helix_view::{graphics::Rect, Editor};
1111use tui::layout::Constraint;
1212
1313pub trait Item {
14− // TODO: sort_text
14+ fn sort_text(&self) -> &str;
1515 fn filter_text(&self) -> &str;
1616
1717 fn label(&self) -> &str;
@@ -64,24 +64,21 @@ impl<T: Item> Menu<T> {
6464 let Self {
6565 ref mut matcher,
6666 ref mut matches,
67+ ref options,
6768 ..
6869 } = *self;
6970
7071 // reuse the matches allocation
7172 matches.clear();
72− matches.extend(
73− self.options
74− .iter()
75− .enumerate()
76− .filter_map(|(index, option)| {
77− let text = option.filter_text();
78− // TODO: using fuzzy_indices could give us the char idx for match highlighting
79− matcher
80− .fuzzy_match(text, pattern)
81− .map(|score| (index, score))
82− }),
83− );
84− matches.sort_unstable_by_key(|(_, score)| -score);
73+ matches.extend(options.iter().enumerate().filter_map(|(index, option)| {
74+ let text = option.filter_text();
75+ // TODO: using fuzzy_indices could give us the char idx for match highlighting
76+ matcher
77+ .fuzzy_match(text, pattern)
78+ .map(|score| (index, score))
79+ }));
80+ // matches.sort_unstable_by_key(|(_, score)| -score);
81+ matches.sort_unstable_by_key(|(index, _score)| options[*index].sort_text());
8582
8683 // reset cursor position
8784 self.cursor = None;
@@ -223,8 +220,6 @@ impl<T: Item + 'static> Component for Menu<T> {
223220 EventResult::Ignored
224221 }
225222
226− // TODO: completion sorting
227−
228223 fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
229224 let n = self
230225 .options