Skip to content

Commit abf1228

Browse files
committed
search now filters the list first
1 parent 547a9d9 commit abf1228

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn handle_list(app_state: &mut AppState, stdout: &mut StdoutLock) -> Result<()>
3838
if is_searching {
3939
match curr_key {
4040
KeyCode::Esc | KeyCode::Enter => {
41-
is_searching = false; // not sure why rust analyzer thinks this is unused
41+
is_searching = false;
4242
list_state.search_query.clear();
4343
continue;
4444
}

src/list/state.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,27 @@ impl<'a> ListState<'a> {
352352
.app_state
353353
.exercises()
354354
.iter()
355+
.filter_map(|exercise| {
356+
match self.filter() {
357+
Filter::None => {
358+
Some(exercise)
359+
},
360+
Filter::Done => {
361+
if exercise.done {
362+
Some(exercise)
363+
} else {
364+
None
365+
}
366+
},
367+
Filter::Pending => {
368+
if !exercise.done {
369+
Some(exercise)
370+
} else {
371+
None
372+
}
373+
}
374+
}
375+
})
355376
.enumerate()
356377
.find_map(|(i, s)| {
357378
if s.name.contains(self.search_query.as_str()) {
@@ -363,8 +384,6 @@ impl<'a> ListState<'a> {
363384

364385
match idx {
365386
Some(i) => {
366-
// ? do we need this function call?
367-
// let exercise_ind = self.selected_to_exercise_ind(i).unwrap();
368387
let exercise_ind = i;
369388
self.scroll_state.set_selected(exercise_ind);
370389
self.update_rows();

0 commit comments

Comments
 (0)