File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -37,10 +37,9 @@ impl<'c> SelectionView<'c> {
37
37
. iter ( )
38
38
. filter ( |emoji| search_text. is_empty ( ) || emoji. contains ( & pattern) )
39
39
. 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 ( ) ) ) ;
44
43
45
44
FilteredView {
46
45
emojis,
@@ -50,6 +49,16 @@ impl<'c> SelectionView<'c> {
50
49
}
51
50
}
52
51
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
+
53
62
pub struct FilteredView < ' s , ' c > {
54
63
emojis : Vec < & ' s Emoji > ,
55
64
state : & ' s mut TableState ,
You can’t perform that action at this time.
0 commit comments