search now filters the list first

This commit is contained in:
Adhyan 2024-09-02 10:59:23 -06:00
parent 547a9d947b
commit abf1228a0a
2 changed files with 22 additions and 3 deletions

View file

@ -38,7 +38,7 @@ fn handle_list(app_state: &mut AppState, stdout: &mut StdoutLock) -> Result<()>
if is_searching {
match curr_key {
KeyCode::Esc | KeyCode::Enter => {
is_searching = false; // not sure why rust analyzer thinks this is unused
is_searching = false;
list_state.search_query.clear();
continue;
}

View file

@ -352,6 +352,27 @@ impl<'a> ListState<'a> {
.app_state
.exercises()
.iter()
.filter_map(|exercise| {
match self.filter() {
Filter::None => {
Some(exercise)
},
Filter::Done => {
if exercise.done {
Some(exercise)
} else {
None
}
},
Filter::Pending => {
if !exercise.done {
Some(exercise)
} else {
None
}
}
}
})
.enumerate()
.find_map(|(i, s)| {
if s.name.contains(self.search_query.as_str()) {
@ -363,8 +384,6 @@ impl<'a> ListState<'a> {
match idx {
Some(i) => {
// ? do we need this function call?
// let exercise_ind = self.selected_to_exercise_ind(i).unwrap();
let exercise_ind = i;
self.scroll_state.set_selected(exercise_ind);
self.update_rows();