From 4691dd05d1c4363af2ec6819a73de65d00ccf79b Mon Sep 17 00:00:00 2001 From: Patrick Auernig Date: Fri, 6 Dec 2024 21:19:19 +0100 Subject: [PATCH] feat(tui): Make search case insensitive by default --- src/tui.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/tui.rs b/src/tui.rs index c0dc408..e660142 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -248,13 +248,25 @@ fn fuzzy_search(search: &str, text: &str) -> Option> { let mut found_indices = Vec::new(); let mut start_idx = 0; - for ch in search.chars() { + let mut case_sensitive = false; + + for (ch_idx, ch) in search.char_indices() { + if ch_idx == 0 { + case_sensitive = ch.is_uppercase(); + } + let remaining = &text[start_idx..]; let mut found = false; for (byte_idx, txt_ch) in remaining.char_indices() { - if ch == txt_ch { + let matching = if case_sensitive { + ch == txt_ch + } else { + ch.to_lowercase().cmp(txt_ch.to_lowercase()).is_eq() + }; + + if matching { found_indices.push(start_idx + byte_idx); start_idx += byte_idx + txt_ch.len_utf8(); found = true;