on master help sign in
Don't just filter commands by fuzzy match, also order the matches
a066f59Blaž Hrastnik
helix-term/src/commands.rs+12−4
@@ -3074,11 +3074,19 @@ fn command_mode(cx: &mut Context) {
3074 // simple heuristic: if there's no just one part, complete command name.
3074 // simple heuristic: if there's no just one part, complete command name.
3075 // if there's a space, per command completion kicks in.
3075 // if there's a space, per command completion kicks in.
3076 if parts.len() <= 1 {
3076 if parts.len() <= 1 {
3077− let end = 0..;
3078− cmd::TYPABLE_COMMAND_LIST
3077+ let mut matches: Vec<_> = cmd::TYPABLE_COMMAND_LIST
3079 .iter()
3078 .iter()
3079+ .filter_map(|command| {
3080+ FUZZY_MATCHER
3080− .filter(|command| FUZZY_MATCHER.fuzzy_match(command.name, input).is_some())
3081+ .fuzzy_match(command.name, input)
3081− .map(|command| (end.clone(), Cow::Borrowed(command.name)))
3082+ .map(|score| (command.name, score))
3083+ })
3084+ .collect();
3085+
3086+ matches.sort_unstable_by_key(|(_file, score)| std::cmp::Reverse(*score));
3087+ matches
3088+ .into_iter()
3089+ .map(|(name, _)| (0.., name.into()))
3082 .collect()
3090 .collect()
3083 } else {
3091 } else {
3084 let part = parts.last().unwrap();
3092 let part = parts.last().unwrap();