Skip to content

Commit f94b500

Browse files
authored
Merge pull request #966 from hecrj/pick-list-scroll-modifier
Allow `PickList` selection with mouse scroll only if command is pressed
2 parents 1cef6a2 + 78b345b commit f94b500

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

native/src/widget/pick_list.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Display a dropdown list of selectable values.
22
use crate::event::{self, Event};
3+
use crate::keyboard;
34
use crate::layout;
45
use crate::mouse;
56
use crate::overlay;
@@ -20,6 +21,7 @@ where
2021
[T]: ToOwned<Owned = Vec<T>>,
2122
{
2223
menu: &'a mut menu::State,
24+
keyboard_modifiers: &'a mut keyboard::Modifiers,
2325
is_open: &'a mut bool,
2426
hovered_option: &'a mut Option<usize>,
2527
last_selection: &'a mut Option<T>,
@@ -38,6 +40,7 @@ where
3840
#[derive(Debug, Clone)]
3941
pub struct State<T> {
4042
menu: menu::State,
43+
keyboard_modifiers: keyboard::Modifiers,
4144
is_open: bool,
4245
hovered_option: Option<usize>,
4346
last_selection: Option<T>,
@@ -47,6 +50,7 @@ impl<T> Default for State<T> {
4750
fn default() -> Self {
4851
Self {
4952
menu: menu::State::default(),
53+
keyboard_modifiers: keyboard::Modifiers::default(),
5054
is_open: bool::default(),
5155
hovered_option: Option::default(),
5256
last_selection: Option::default(),
@@ -71,13 +75,15 @@ where
7175
) -> Self {
7276
let State {
7377
menu,
78+
keyboard_modifiers,
7479
is_open,
7580
hovered_option,
7681
last_selection,
7782
} = state;
7883

7984
Self {
8085
menu,
86+
keyboard_modifiers,
8187
is_open,
8288
hovered_option,
8389
last_selection,
@@ -270,7 +276,8 @@ where
270276
}
271277
Event::Mouse(mouse::Event::WheelScrolled {
272278
delta: mouse::ScrollDelta::Lines { y, .. },
273-
}) if layout.bounds().contains(cursor_position)
279+
}) if self.keyboard_modifiers.command()
280+
&& layout.bounds().contains(cursor_position)
274281
&& !*self.is_open =>
275282
{
276283
fn find_next<'a, T: PartialEq>(
@@ -302,9 +309,13 @@ where
302309
messages.push((self.on_selected)(next_option.clone()));
303310
}
304311

305-
return event::Status::Captured;
312+
event::Status::Captured
306313
}
314+
Event::Keyboard(keyboard::Event::ModifiersChanged(modifiers)) => {
315+
*self.keyboard_modifiers = modifiers;
307316

317+
event::Status::Ignored
318+
}
308319
_ => event::Status::Ignored,
309320
}
310321
}

0 commit comments

Comments
 (0)