@@ -37,14 +37,14 @@ pub enum Filter {
3737pub struct ListState < ' a > {
3838 /// Footer message to be displayed if not empty.
3939 pub message : String ,
40+ pub search_query : String ,
4041 app_state : & ' a mut AppState ,
4142 scroll_state : ScrollState ,
4243 name_col_padding : Vec < u8 > ,
4344 filter : Filter ,
4445 term_width : u16 ,
4546 term_height : u16 ,
4647 show_footer : bool ,
47- pub search_query : String ,
4848}
4949
5050impl < ' a > ListState < ' a > {
@@ -69,6 +69,7 @@ impl<'a> ListState<'a> {
6969
7070 let mut slf = Self {
7171 message : String :: with_capacity ( 128 ) ,
72+ search_query : String :: new ( ) ,
7273 app_state,
7374 scroll_state,
7475 name_col_padding,
@@ -77,7 +78,6 @@ impl<'a> ListState<'a> {
7778 term_width : 0 ,
7879 term_height : 0 ,
7980 show_footer : true ,
80- search_query : String :: new ( ) ,
8181 } ;
8282
8383 slf. set_term_size ( width, height) ;
@@ -356,25 +356,20 @@ impl<'a> ListState<'a> {
356356 return ;
357357 }
358358
359- let idx = self
359+ let ind = self
360360 . app_state
361361 . exercises ( )
362362 . iter ( )
363- . filter ( |exercise| match self . filter ( ) {
363+ . filter ( |exercise| match self . filter {
364364 Filter :: None => true ,
365365 Filter :: Done => exercise. done ,
366366 Filter :: Pending => !exercise. done ,
367367 } )
368368 . position ( |exercise| exercise. name . contains ( self . search_query . as_str ( ) ) ) ;
369369
370- match idx {
371- Some ( exercise_ind) => {
372- self . scroll_state . set_selected ( exercise_ind) ;
373- }
374- None => {
375- let msg = String :: from ( " (not found)" ) ;
376- self . message . push_str ( & msg) ;
377- }
370+ match ind {
371+ Some ( exercise_ind) => self . scroll_state . set_selected ( exercise_ind) ,
372+ None => self . message . push_str ( " (not found)" ) ,
378373 }
379374 }
380375
0 commit comments