Skip to content

Commit a83d381

Browse files
committed
fix(winit): pass text with modifiers in event
1 parent 9499727 commit a83d381

1 file changed

Lines changed: 48 additions & 42 deletions

File tree

winit/src/conversion.rs

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
//!
33
//! [`winit`]: https://github.com/rust-windowing/winit
44
//! [`iced_runtime`]: https://github.com/iced-rs/iced/tree/0.10/runtime
5+
use winit::keyboard::SmolStr;
6+
use winit::platform::modifier_supplement::KeyEventExtModifierSupplement;
7+
58
use crate::core::keyboard;
69
use crate::core::mouse;
710
use crate::core::touch;
@@ -195,51 +198,54 @@ pub fn window_event(
195198
}))
196199
}
197200
},
198-
WindowEvent::KeyboardInput {
199-
event:
200-
winit::event::KeyEvent {
201-
logical_key,
202-
state,
203-
text,
204-
location,
205-
..
206-
},
207-
..
208-
} => Some(Event::Keyboard({
209-
let key = key(logical_key);
210-
let modifiers = self::modifiers(modifiers);
211-
212-
let location = match location {
213-
winit::keyboard::KeyLocation::Standard => {
214-
keyboard::Location::Standard
215-
}
216-
winit::keyboard::KeyLocation::Left => keyboard::Location::Left,
217-
winit::keyboard::KeyLocation::Right => {
218-
keyboard::Location::Right
219-
}
220-
winit::keyboard::KeyLocation::Numpad => {
221-
keyboard::Location::Numpad
222-
}
223-
};
224-
225-
match state {
226-
winit::event::ElementState::Pressed => {
227-
keyboard::Event::KeyPressed {
228-
key,
229-
modifiers,
230-
location,
231-
text,
201+
WindowEvent::KeyboardInput { event, .. } => {
202+
let text_with_modifiers =
203+
event.text_with_all_modifiers().map(|t| SmolStr::new(t));
204+
let winit::event::KeyEvent {
205+
logical_key,
206+
state,
207+
text: _text,
208+
location,
209+
..
210+
} = event;
211+
Some(Event::Keyboard({
212+
let key = key(logical_key);
213+
let modifiers = self::modifiers(modifiers);
214+
215+
let location = match location {
216+
winit::keyboard::KeyLocation::Standard => {
217+
keyboard::Location::Standard
232218
}
233-
}
234-
winit::event::ElementState::Released => {
235-
keyboard::Event::KeyReleased {
236-
key,
237-
modifiers,
238-
location,
219+
winit::keyboard::KeyLocation::Left => {
220+
keyboard::Location::Left
221+
}
222+
winit::keyboard::KeyLocation::Right => {
223+
keyboard::Location::Right
224+
}
225+
winit::keyboard::KeyLocation::Numpad => {
226+
keyboard::Location::Numpad
227+
}
228+
};
229+
230+
match state {
231+
winit::event::ElementState::Pressed => {
232+
keyboard::Event::KeyPressed {
233+
key,
234+
modifiers,
235+
location,
236+
text: text_with_modifiers,
237+
}
238+
}
239+
winit::event::ElementState::Released => {
240+
keyboard::Event::KeyReleased {
241+
key,
242+
modifiers,
243+
location,
244+
}
239245
}
240246
}
241-
}
242-
})),
247+
}))
248+
}
243249
WindowEvent::ModifiersChanged(new_modifiers) => {
244250
Some(Event::Keyboard(keyboard::Event::ModifiersChanged(
245251
self::modifiers(new_modifiers.state()),

0 commit comments

Comments
 (0)