Skip to content

Commit

Permalink
fix(filter): prevent panic after tab completing
Browse files Browse the repository at this point in the history
After tab completing if you would press
a key other than return (enter) then the
tui would panic, this change fixes that
issue.
  • Loading branch information
nnyyxxxx committed Feb 12, 2025
1 parent c12ae4a commit de3d019
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tui/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
}
}
Expand Down

0 comments on commit de3d019

Please sign in to comment.