Skip to content

Commit

Permalink
fix: select might panic when filtering multi-page options (jdx#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
roele committed Jan 17, 2024
1 parent dbd4019 commit 83b7d51
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ impl<T: Display> Select<T> {
Key::Char('/') if self.filterable => self.handle_start_filtering(),
Key::Escape => self.handle_stop_filtering(false),
Key::Enter => {
// if the cursor is on an empty option, don't return it
if self.visible_options().get(self.cursor).is_none() {
self.handle_stop_filtering(false);
continue;
}
self.clear()?;
self.term.show_cursor()?;
let id = self.visible_options().get(self.cursor).unwrap().id;
Expand Down Expand Up @@ -196,6 +201,7 @@ impl<T: Display> Select<T> {

fn handle_stop_filtering(&mut self, save: bool) {
self.filtering = false;
self.cur_page = 0;

let visible_options = self.visible_options();
if !visible_options.is_empty() {
Expand Down

0 comments on commit 83b7d51

Please sign in to comment.