From 902c19bfbb64f5c6690fc4e95db25dda86eeb777 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sun, 14 Apr 2024 23:30:22 +0800 Subject: [PATCH] Simplify the code --- yazi-core/src/completion/commands/show.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/yazi-core/src/completion/commands/show.rs b/yazi-core/src/completion/commands/show.rs index d29f0edf..0ba8a25d 100644 --- a/yazi-core/src/completion/commands/show.rs +++ b/yazi-core/src/completion/commands/show.rs @@ -26,15 +26,12 @@ impl From for Opt { impl Completion { fn match_candidates(word: &str, cache: &[String]) -> Vec { + 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 {