fix(filter): prevent panic after tab completing

After tab completing if you would press
a key other than return (enter) then the
tui would panic, this change fixes that
issue.
This commit is contained in:
nnyyxxxx 2025-02-12 04:11:57 -05:00
parent c12ae4a8ef
commit de3d01922b
No known key found for this signature in database
GPG Key ID: 6038FFD6589902CB

View File

@ -92,8 +92,16 @@ impl Filter {
let input = self.search_input.iter().collect::<String>().to_lowercase();
self.items.iter().find_map(|item| {
let item_name_lower = item.node.name.to_lowercase();
(item_name_lower.starts_with(&input))
.then_some(item_name_lower[input.len()..].to_string())
item_name_lower
.starts_with(&input)
.then(|| {
if input.len() <= item_name_lower.len() {
Some(item_name_lower[input.len()..].to_string())
} else {
None
}
})
.flatten()
})
}
}