feat(tui): Make search case insensitive by default
This commit is contained in:
parent
e7bb664cc2
commit
4691dd05d1
16
src/tui.rs
16
src/tui.rs
@ -248,13 +248,25 @@ fn fuzzy_search(search: &str, text: &str) -> Option<Vec<usize>> {
|
|||||||
let mut found_indices = Vec::new();
|
let mut found_indices = Vec::new();
|
||||||
let mut start_idx = 0;
|
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 remaining = &text[start_idx..];
|
||||||
|
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
|
|
||||||
for (byte_idx, txt_ch) in remaining.char_indices() {
|
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);
|
found_indices.push(start_idx + byte_idx);
|
||||||
start_idx += byte_idx + txt_ch.len_utf8();
|
start_idx += byte_idx + txt_ch.len_utf8();
|
||||||
found = true;
|
found = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user