Split Input
keyboard event by ButtonState
This commit is contained in:
parent
af95d3972e
commit
e139aae143
@ -1,5 +1,4 @@
|
||||
use super::{KeyCode, ModifiersState};
|
||||
use crate::input::ButtonState;
|
||||
|
||||
/// A keyboard event.
|
||||
///
|
||||
@ -9,11 +8,17 @@ use crate::input::ButtonState;
|
||||
/// [open an issue]: https://github.com/hecrj/iced/issues
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum Event {
|
||||
/// A keyboard key was pressed or released.
|
||||
Input {
|
||||
/// The state of the key
|
||||
state: ButtonState,
|
||||
/// A keyboard key was pressed.
|
||||
KeyPressed {
|
||||
/// The key identifier
|
||||
key_code: KeyCode,
|
||||
|
||||
/// The state of the modifier keys
|
||||
modifiers: ModifiersState,
|
||||
},
|
||||
|
||||
/// A keyboard key was released.
|
||||
KeyReleased {
|
||||
/// The key identifier
|
||||
key_code: KeyCode,
|
||||
|
||||
|
@ -532,31 +532,31 @@ where
|
||||
Event::Mouse(mouse::Event::CursorMoved { .. }) => {
|
||||
self.trigger_resize(layout, cursor_position, messages);
|
||||
}
|
||||
Event::Keyboard(keyboard::Event::Input {
|
||||
Event::Keyboard(keyboard::Event::KeyPressed {
|
||||
modifiers,
|
||||
key_code,
|
||||
state,
|
||||
}) => {
|
||||
if let Some(on_key_press) = &self.on_key_press {
|
||||
// TODO: Discard when event is captured
|
||||
if state == ButtonState::Pressed {
|
||||
if let Some(_) = self.state.active_pane() {
|
||||
if modifiers.matches(self.modifier_keys) {
|
||||
if let Some(message) =
|
||||
on_key_press(KeyPressEvent {
|
||||
if let Some(message) = on_key_press(KeyPressEvent {
|
||||
key_code,
|
||||
modifiers,
|
||||
})
|
||||
{
|
||||
}) {
|
||||
messages.push(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*self.pressed_modifiers = modifiers;
|
||||
}
|
||||
Event::Keyboard(keyboard::Event::KeyReleased {
|
||||
modifiers, ..
|
||||
}) => {
|
||||
*self.pressed_modifiers = modifiers;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
@ -327,9 +327,8 @@ where
|
||||
let message = (self.on_change)(editor.contents());
|
||||
messages.push(message);
|
||||
}
|
||||
Event::Keyboard(keyboard::Event::Input {
|
||||
Event::Keyboard(keyboard::Event::KeyPressed {
|
||||
key_code,
|
||||
state: ButtonState::Pressed,
|
||||
modifiers,
|
||||
}) if self.state.is_focused => match key_code {
|
||||
keyboard::KeyCode::Enter => {
|
||||
@ -473,10 +472,8 @@ where
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
Event::Keyboard(keyboard::Event::Input {
|
||||
key_code,
|
||||
state: ButtonState::Released,
|
||||
..
|
||||
Event::Keyboard(keyboard::Event::KeyReleased {
|
||||
key_code, ..
|
||||
}) => match key_code {
|
||||
keyboard::KeyCode::V => {
|
||||
self.state.is_pasting = None;
|
||||
|
@ -70,10 +70,24 @@ pub fn window_event(
|
||||
..
|
||||
},
|
||||
..
|
||||
} => Some(Event::Keyboard(keyboard::Event::Input {
|
||||
key_code: key_code(*virtual_keycode),
|
||||
state: button_state(*state),
|
||||
modifiers: modifiers_state(modifiers),
|
||||
} => Some(Event::Keyboard({
|
||||
let key_code = key_code(*virtual_keycode);
|
||||
let modifiers = modifiers_state(modifiers);
|
||||
|
||||
match state {
|
||||
winit::event::ElementState::Pressed => {
|
||||
keyboard::Event::KeyPressed {
|
||||
key_code,
|
||||
modifiers,
|
||||
}
|
||||
}
|
||||
winit::event::ElementState::Released => {
|
||||
keyboard::Event::KeyReleased {
|
||||
key_code,
|
||||
modifiers,
|
||||
}
|
||||
}
|
||||
}
|
||||
})),
|
||||
WindowEvent::HoveredFile(path) => {
|
||||
Some(Event::Window(window::Event::FileHovered(path.clone())))
|
||||
|
Loading…
Reference in New Issue
Block a user