Skip to content

Commit

Permalink
fix: multiselect clear when filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
Vulpesx committed May 11, 2024
1 parent 3711d74 commit fda8e44
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/multiselect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ impl<'a, T> MultiSelect<'a, T> {
self.height = output.lines().count() - 1;
if self.filtering {
match self.term.read_key()? {
Key::Enter => self.handle_stop_filtering(true),
Key::Escape => self.handle_stop_filtering(false),
Key::Backspace => self.handle_filter_backspace(),
Key::Char(c) => self.handle_filter_key(c),
Key::Enter => self.handle_stop_filtering(true)?,
Key::Escape => self.handle_stop_filtering(false)?,
Key::Backspace => self.handle_filter_backspace()?,
Key::Char(c) => self.handle_filter_key(c)?,
_ => {}
}
} else {
Expand All @@ -155,7 +155,7 @@ impl<'a, T> MultiSelect<'a, T> {
Key::Char('x') | Key::Char(' ') => self.handle_toggle(),
Key::Char('a') => self.handle_toggle_all(),
Key::Char('/') if self.filterable => self.handle_start_filtering(),
Key::Escape => self.handle_stop_filtering(false),
Key::Escape => self.handle_stop_filtering(false)?,
Key::Enter => {
let selected = self
.options
Expand Down Expand Up @@ -300,7 +300,7 @@ impl<'a, T> MultiSelect<'a, T> {
self.filtering = true;
}

fn handle_stop_filtering(&mut self, save: bool) {
fn handle_stop_filtering(&mut self, save: bool) -> Result<(), io::Error> {
self.filtering = false;

let visible_options = self.visible_options();
Expand All @@ -311,18 +311,21 @@ impl<'a, T> MultiSelect<'a, T> {
self.filter.clear();
self.reset_paging();
}
self.term.clear_to_end_of_screen()
}

fn handle_filter_key(&mut self, c: char) {
fn handle_filter_key(&mut self, c: char) -> Result<(), io::Error> {
self.err = None;
self.filter.push(c);
self.reset_paging();
self.term.clear_to_end_of_screen()
}

fn handle_filter_backspace(&mut self) {
fn handle_filter_backspace(&mut self) -> Result<(), io::Error> {
self.err = None;
self.filter.pop();
self.reset_paging();
self.term.clear_to_end_of_screen()
}

fn reset_paging(&mut self) {
Expand Down

0 comments on commit fda8e44

Please sign in to comment.