File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,10 +37,9 @@ impl<'c> SelectionView<'c> {
3737 . iter ( )
3838 . filter ( |emoji| search_text. is_empty ( ) || emoji. contains ( & pattern) )
3939 . collect ( ) ;
40- if self . state . selected ( ) . unwrap ( ) >= emojis. len ( ) {
41- // Reset the selection if the list goes shorter than the selected index.
42- self . state . select ( Some ( 0 ) ) ;
43- }
40+
41+ self . state
42+ . select ( adjust_selected ( self . state . selected ( ) , emojis. len ( ) ) ) ;
4443
4544 FilteredView {
4645 emojis,
@@ -50,6 +49,16 @@ impl<'c> SelectionView<'c> {
5049 }
5150}
5251
52+ fn adjust_selected ( selected : Option < usize > , list_len : usize ) -> Option < usize > {
53+ match ( selected, list_len) {
54+ ( _, 0 ) => None ,
55+ ( None , _) => Some ( 0 ) ,
56+ // Reset the selection if the list goes shorter than the selected index.
57+ ( Some ( selected) , _) if selected >= list_len => Some ( 0 ) ,
58+ ( Some ( _) , _) => selected,
59+ }
60+ }
61+
5362pub struct FilteredView < ' s , ' c > {
5463 emojis : Vec < & ' s Emoji > ,
5564 state : & ' s mut TableState ,
You can’t perform that action at this time.
0 commit comments