Skip to content

Commit

Permalink
Match filter once
Browse files Browse the repository at this point in the history
  • Loading branch information
mo8it committed Sep 3, 2024
1 parent 03baa47 commit e5ed115
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/list/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,16 +356,17 @@ impl<'a> ListState<'a> {
return;
}

let ind = self
.app_state
.exercises()
.iter()
.filter(|exercise| match self.filter {
Filter::None => true,
Filter::Done => exercise.done,
Filter::Pending => !exercise.done,
})
.position(|exercise| exercise.name.contains(self.search_query.as_str()));
let is_search_result = |exercise: &Exercise| exercise.name.contains(&self.search_query);
let mut iter = self.app_state.exercises().iter();
let ind = match self.filter {
Filter::None => iter.position(is_search_result),
Filter::Done => iter
.filter(|exercise| exercise.done)
.position(is_search_result),
Filter::Pending => iter
.filter(|exercise| !exercise.done)
.position(is_search_result),
};

match ind {
Some(exercise_ind) => self.scroll_state.set_selected(exercise_ind),
Expand Down

0 comments on commit e5ed115

Please sign in to comment.