Skip to content

Commit d3f451a

Browse files
committed
fix: handle non-ASCII chars in entry filtering
1 parent c4cb3bd commit d3f451a

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/file_handling/mod.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -620,32 +620,39 @@ impl Explorer {
620620

621621
pub fn find_entries_with_initial(&self, initial: char) -> Option<FilteredEntries> {
622622
let parent_dir_entry = parent_dir_entry();
623-
let initial_lower = initial.to_ascii_lowercase() as u8; // Avoid recalculating this for each item
624-
623+
let initial_lower = initial.to_lowercase().next(); // Get the first character after lowercasing
624+
625+
// If initial_lower is None (rare, but possible), return None early
626+
let initial_lower = match initial_lower {
627+
Some(c) => c,
628+
None => return None,
629+
};
630+
625631
let entries: Vec<_> = self
626632
.items
627633
.iter()
628634
.filter(|item| !item.name.starts_with(&parent_dir_entry)) // Remove parent directory entry
629635
.enumerate() // Attach indices to items
630636
.filter_map(|(index, item)| {
631637
item.name
632-
.as_bytes()
633-
.first()
634-
.map(|&c| c.to_ascii_lowercase()) // Get first character efficiently
638+
.chars()
639+
.next() // Get the first character of the name
640+
.and_then(|c| c.to_lowercase().next()) // Lowercase and get the first character
635641
.filter(|&c| c == initial_lower) // Compare without case sensitivity
636642
.map(|_| match self.cwd.parent() {
637643
Some(_) => index + 1, // Adjust index if parent exists
638644
None => index,
639645
})
640646
})
641647
.collect();
642-
648+
643649
if entries.is_empty() {
644650
None
645651
} else {
646652
Some(FilteredEntries::new(initial, entries))
647653
}
648654
}
655+
649656

650657
pub fn find_entries_by_name(
651658
tx: UnboundedSender<Action>,

0 commit comments

Comments
 (0)