diff options
author | Blaž Hrastnik | 2021-12-30 06:20:22 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-12-30 06:20:22 +0000 |
commit | a066f59dc87608935ef4a3a3df3edf180c809e11 (patch) | |
tree | 28aa8ffc9318e8580f334f0ae6b293f75080028b /helix-term/src | |
parent | bcf3808e9763bfe1bbf70f6053f890c80639d7c9 (diff) |
Don't just filter commands by fuzzy match, also order the matches
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/commands.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 9d7d11eb..6259ecb2 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -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(); |