mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-25 23:10:30 +00:00
Match filter once
This commit is contained in:
parent
03baa471d9
commit
e5ed115288
1 changed files with 11 additions and 10 deletions
|
@ -356,16 +356,17 @@ impl<'a> ListState<'a> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let ind = self
|
let is_search_result = |exercise: &Exercise| exercise.name.contains(&self.search_query);
|
||||||
.app_state
|
let mut iter = self.app_state.exercises().iter();
|
||||||
.exercises()
|
let ind = match self.filter {
|
||||||
.iter()
|
Filter::None => iter.position(is_search_result),
|
||||||
.filter(|exercise| match self.filter {
|
Filter::Done => iter
|
||||||
Filter::None => true,
|
.filter(|exercise| exercise.done)
|
||||||
Filter::Done => exercise.done,
|
.position(is_search_result),
|
||||||
Filter::Pending => !exercise.done,
|
Filter::Pending => iter
|
||||||
})
|
.filter(|exercise| !exercise.done)
|
||||||
.position(|exercise| exercise.name.contains(self.search_query.as_str()));
|
.position(is_search_result),
|
||||||
|
};
|
||||||
|
|
||||||
match ind {
|
match ind {
|
||||||
Some(exercise_ind) => self.scroll_state.set_selected(exercise_ind),
|
Some(exercise_ind) => self.scroll_state.set_selected(exercise_ind),
|
||||||
|
|
Loading…
Reference in a new issue