diff options
author | 2024-02-20 16:41:54 +0100 | |
---|---|---|
committer | 2024-02-20 16:41:54 +0100 | |
commit | 78dfcfb16a7fa36fed6042c2817b5b46ff54820e (patch) | |
tree | 5ebc4943a2114686e2571d75d933f340e0a6bbfc /winit/src | |
parent | e24b1b65002d716f8bf5fccb49871bd4f46791ca (diff) | |
parent | 4aaa4f2e20cd581827cdb459af54983ff0a41546 (diff) | |
download | iced-78dfcfb16a7fa36fed6042c2817b5b46ff54820e.tar.gz iced-78dfcfb16a7fa36fed6042c2817b5b46ff54820e.tar.bz2 iced-78dfcfb16a7fa36fed6042c2817b5b46ff54820e.zip |
Merge pull request #2238 from wash2/modifiers-text
fix: account for modifiers in key text
Diffstat (limited to '')
-rw-r--r-- | winit/src/conversion.rs | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index 478dbddd..3d2ba0a4 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -195,17 +195,40 @@ pub fn window_event( })) } }, - WindowEvent::KeyboardInput { - event: - winit::event::KeyEvent { - logical_key, - state, - text, - location, - .. - }, - .. - } => Some(Event::Keyboard({ + WindowEvent::KeyboardInput { event, .. } => Some(Event::Keyboard({ + let logical_key = { + #[cfg(not(target_arch = "wasm32"))] + { + use winit::platform::modifier_supplement::KeyEventExtModifierSupplement; + event.key_without_modifiers() + } + + #[cfg(target_arch = "wasm32")] + { + // TODO: Fix inconsistent API on Wasm + event.logical_key + } + }; + + let text = { + #[cfg(not(target_arch = "wasm32"))] + { + use crate::core::SmolStr; + use winit::platform::modifier_supplement::KeyEventExtModifierSupplement; + + event.text_with_all_modifiers().map(SmolStr::new) + } + + #[cfg(target_arch = "wasm32")] + { + // TODO: Fix inconsistent API on Wasm + event.text + } + }; + + let winit::event::KeyEvent { + state, location, .. + } = event; let key = key(logical_key); let modifiers = self::modifiers(modifiers); |