diff --git a/src/list.rs b/src/list.rs index b41c8913..069cdda0 100644 --- a/src/list.rs +++ b/src/list.rs @@ -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; } diff --git a/src/list/state.rs b/src/list/state.rs index be05f3b7..8d5bf5b8 100644 --- a/src/list/state.rs +++ b/src/list/state.rs @@ -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();