Simplify the code

This commit is contained in:
sxyazi 2024-04-14 23:30:22 +08:00
parent 988093b50e
commit 902c19bfbb
No known key found for this signature in database

View file

@ -26,15 +26,12 @@ impl From<Cmd> for Opt {
impl Completion {
fn match_candidates(word: &str, cache: &[String]) -> Vec<String> {
let smart = word.chars().all(|c| c.is_lowercase());
let flow = cache.iter().try_fold(
(Vec::with_capacity(LIMIT), Vec::with_capacity(LIMIT)),
|(mut prefixed, mut fuzzy), s| {
let start_with_word = if word.chars().any(|c| c.is_uppercase()) {
s.starts_with(word)
} else {
s.to_lowercase().starts_with(word)
};
if start_with_word {
if (smart && s.to_lowercase().starts_with(word)) || (!smart && s.starts_with(word)) {
if s != word {
prefixed.push(s);
if prefixed.len() >= LIMIT {