Skip to content

Commit

Permalink
Merge pull request #2238 from wash2/modifiers-text
Browse files Browse the repository at this point in the history
fix: account for modifiers in key text
  • Loading branch information
hecrj authored Feb 20, 2024
2 parents e24b1b6 + 4aaa4f2 commit 78dfcfb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Black images when using OpenGL backend in `iced_wgpu`. [#2259](https://github.com/iced-rs/iced/pull/2259)
- Documentation for `horizontal_space` and `vertical_space` helpers. [#2265](https://github.com/iced-rs/iced/pull/2265)
- WebAssembly platform. [#2271](https://github.com/iced-rs/iced/pull/2271)
- Decouple `Key` from `keyboard::Modifiers` and apply them to `text` in `KeyboardInput`. [#2238](https://github.com/iced-rs/iced/pull/2238)

Many thanks to...

- @PolyMeilex
- @rizzen-yazston
- @wash2

## [0.12.0] - 2024-02-15
### Added
Expand Down
45 changes: 34 additions & 11 deletions winit/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 78dfcfb

Please sign in to comment.