Skip to content

Commit

Permalink
fix: [select] arrow keys should work while filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
roele authored and jdx committed Dec 12, 2024
1 parent 0811b3e commit 678876f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ impl<'a, T> Select<'a, T> {
};
if self.filtering {
match self.term.read_key()? {
Key::ArrowDown => self.handle_down()?,
Key::ArrowUp => self.handle_up()?,
Key::ArrowLeft => self.handle_left()?,
Key::ArrowRight => self.handle_right()?,
Key::Enter => return enter(self),
Key::Escape => self.handle_stop_filtering(false)?,
Key::Backspace => self.handle_filter_backspace()?,
Expand Down Expand Up @@ -233,6 +237,7 @@ impl<'a, T> Select<'a, T> {

fn handle_left(&mut self) -> Result<(), io::Error> {
if self.cur_page > 0 {
self.cursor = 0;
self.cur_page -= 1;
self.term.clear_to_end_of_screen()?;
}
Expand All @@ -241,6 +246,7 @@ impl<'a, T> Select<'a, T> {

fn handle_right(&mut self) -> Result<(), io::Error> {
if self.pages > 0 && self.cur_page < self.pages - 1 {
self.cursor = 0;
self.cur_page += 1;
self.term.clear_to_end_of_screen()?;
}
Expand All @@ -264,13 +270,15 @@ impl<'a, T> Select<'a, T> {

fn handle_filter_key(&mut self, c: char) -> Result<(), io::Error> {
self.filter.push(c);
self.cursor = 0;
self.cur_page = 0;
self.pages = self.get_pages();
self.term.clear_to_end_of_screen()
}

fn handle_filter_backspace(&mut self) -> Result<(), io::Error> {
self.filter.pop();
self.cursor = 0;
self.cur_page = 0;
self.pages = self.get_pages();
self.term.clear_to_end_of_screen()
Expand Down

0 comments on commit 678876f

Please sign in to comment.