Skip to content

Commit e5ed115

Browse files
committed
Match filter once
1 parent 03baa47 commit e5ed115

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/list/state.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -356,16 +356,17 @@ impl<'a> ListState<'a> {
356356
return;
357357
}
358358

359-
let ind = self
360-
.app_state
361-
.exercises()
362-
.iter()
363-
.filter(|exercise| match self.filter {
364-
Filter::None => true,
365-
Filter::Done => exercise.done,
366-
Filter::Pending => !exercise.done,
367-
})
368-
.position(|exercise| exercise.name.contains(self.search_query.as_str()));
359+
let is_search_result = |exercise: &Exercise| exercise.name.contains(&self.search_query);
360+
let mut iter = self.app_state.exercises().iter();
361+
let ind = match self.filter {
362+
Filter::None => iter.position(is_search_result),
363+
Filter::Done => iter
364+
.filter(|exercise| exercise.done)
365+
.position(is_search_result),
366+
Filter::Pending => iter
367+
.filter(|exercise| !exercise.done)
368+
.position(is_search_result),
369+
};
369370

370371
match ind {
371372
Some(exercise_ind) => self.scroll_state.set_selected(exercise_ind),

0 commit comments

Comments
 (0)