This commit is contained in:
Adhyan
2024-09-01 18:56:52 -06:00
4 changed files with 91 additions and 4 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ impl ScrollState {
self.selected
}
fn set_selected(&mut self, selected: usize) {
pub fn set_selected(&mut self, selected: usize) {
self.selected = Some(selected);
self.update_offset();
}
+37
View File
@@ -44,6 +44,7 @@ pub struct ListState<'a> {
term_width: u16,
term_height: u16,
show_footer: bool,
pub search_query: String,
}
impl<'a> ListState<'a> {
@@ -76,6 +77,7 @@ impl<'a> ListState<'a> {
term_width: 0,
term_height: 0,
show_footer: true,
search_query: String::new(),
};
slf.set_term_size(width, height);
@@ -344,6 +346,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> {