diff options
Diffstat (limited to 'src/list/state.rs')
| -rw-r--r-- | src/list/state.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/list/state.rs b/src/list/state.rs index 49b6d5d..117740c 100644 --- a/src/list/state.rs +++ b/src/list/state.rs @@ -45,6 +45,7 @@ pub struct ListState<'a> { term_height: u16, separator_line: Vec<u8>, show_footer: bool, + pub search_query: String, } impl<'a> ListState<'a> { @@ -78,6 +79,7 @@ impl<'a> ListState<'a> { term_height: 0, separator_line: Vec::new(), show_footer: true, + search_query: String::new(), }; slf.set_term_size(width, height); @@ -356,6 +358,41 @@ impl<'a> ListState<'a> { Ok(()) } + + pub fn select_if_matches_search_query(&mut self) { + eprintln!("search query: {:?}", self.search_query); + + let idx = self + .app_state + .exercises() + .iter() + .enumerate() + .find_map(|(i, s)| { + if s.name.contains(self.search_query.as_str()) { + Some(i) + } else { + None + } + }); + eprintln!("idx: {:?}", idx); + + 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); + eprintln!("exercise_ind: {:?}", exercise_ind); + self.update_rows(); + } + None => { + let msg = String::from("[NOT FOUND]") + &self.message.clone(); + self.message.clear(); + self.message.push_str(&msg); + } + } + + } // Return `true` if there was something to select. pub fn selected_to_current_exercise(&mut self) -> Result<bool> { |
