Skip to content

Commit

Permalink
search now filters the list first
Browse files Browse the repository at this point in the history
  • Loading branch information
frroossst committed Sep 2, 2024
1 parent 547a9d9 commit abf1228
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
23 changes: 21 additions & 2 deletions src/list/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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();
Expand Down

0 comments on commit abf1228

Please sign in to comment.