Skip to content

Commit

Permalink
Don't just filter commands by fuzzy match, also order the matches
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Dec 30, 2021
1 parent bcf3808 commit a066f59
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3074,11 +3074,19 @@ fn command_mode(cx: &mut Context) {
// simple heuristic: if there's no just one part, complete command name.
// if there's a space, per command completion kicks in.
if parts.len() <= 1 {
let end = 0..;
cmd::TYPABLE_COMMAND_LIST
let mut matches: Vec<_> = cmd::TYPABLE_COMMAND_LIST
.iter()
.filter(|command| FUZZY_MATCHER.fuzzy_match(command.name, input).is_some())
.map(|command| (end.clone(), Cow::Borrowed(command.name)))
.filter_map(|command| {
FUZZY_MATCHER
.fuzzy_match(command.name, input)
.map(|score| (command.name, score))
})
.collect();

matches.sort_unstable_by_key(|(_file, score)| std::cmp::Reverse(*score));
matches
.into_iter()
.map(|(name, _)| (0.., name.into()))
.collect()
} else {
let part = parts.last().unwrap();
Expand Down

0 comments on commit a066f59

Please sign in to comment.