1
1
//! Display a dropdown list of selectable values.
2
2
use crate :: event:: { self , Event } ;
3
+ use crate :: keyboard;
3
4
use crate :: layout;
4
5
use crate :: mouse;
5
6
use crate :: overlay;
20
21
[ T ] : ToOwned < Owned = Vec < T > > ,
21
22
{
22
23
menu : & ' a mut menu:: State ,
24
+ keyboard_modifiers : & ' a mut keyboard:: Modifiers ,
23
25
is_open : & ' a mut bool ,
24
26
hovered_option : & ' a mut Option < usize > ,
25
27
last_selection : & ' a mut Option < T > ,
38
40
#[ derive( Debug , Clone ) ]
39
41
pub struct State < T > {
40
42
menu : menu:: State ,
43
+ keyboard_modifiers : keyboard:: Modifiers ,
41
44
is_open : bool ,
42
45
hovered_option : Option < usize > ,
43
46
last_selection : Option < T > ,
@@ -47,6 +50,7 @@ impl<T> Default for State<T> {
47
50
fn default ( ) -> Self {
48
51
Self {
49
52
menu : menu:: State :: default ( ) ,
53
+ keyboard_modifiers : keyboard:: Modifiers :: default ( ) ,
50
54
is_open : bool:: default ( ) ,
51
55
hovered_option : Option :: default ( ) ,
52
56
last_selection : Option :: default ( ) ,
@@ -71,13 +75,15 @@ where
71
75
) -> Self {
72
76
let State {
73
77
menu,
78
+ keyboard_modifiers,
74
79
is_open,
75
80
hovered_option,
76
81
last_selection,
77
82
} = state;
78
83
79
84
Self {
80
85
menu,
86
+ keyboard_modifiers,
81
87
is_open,
82
88
hovered_option,
83
89
last_selection,
@@ -270,7 +276,8 @@ where
270
276
}
271
277
Event :: Mouse ( mouse:: Event :: WheelScrolled {
272
278
delta : mouse:: ScrollDelta :: Lines { y, .. } ,
273
- } ) if layout. bounds ( ) . contains ( cursor_position)
279
+ } ) if self . keyboard_modifiers . command ( )
280
+ && layout. bounds ( ) . contains ( cursor_position)
274
281
&& !* self . is_open =>
275
282
{
276
283
fn find_next < ' a , T : PartialEq > (
@@ -302,9 +309,13 @@ where
302
309
messages. push ( ( self . on_selected ) ( next_option. clone ( ) ) ) ;
303
310
}
304
311
305
- return event:: Status :: Captured ;
312
+ event:: Status :: Captured
306
313
}
314
+ Event :: Keyboard ( keyboard:: Event :: ModifiersChanged ( modifiers) ) => {
315
+ * self . keyboard_modifiers = modifiers;
307
316
317
+ event:: Status :: Ignored
318
+ }
308
319
_ => event:: Status :: Ignored ,
309
320
}
310
321
}
0 commit comments