mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-26 22:53:15 -04:00
fix(android): Populate KeyEvent.text via Key::to_text()
The `text` field on `KeyEvent` was hardcoded to `None` on Android, making it impossible for custom `NativeActivity` subclasses that show the IME to receive functional text input using *for example* the existing `winit-egui` crate which relies on this field being set. Use `Key::to_text()` on press events to derive `text` from `logical_key`, matching the convention used by the Windows and macOS backends. Supposedly that doesn't include all kinds of special virtual unicode keys, but at least the basics work this way.
This commit is contained in:
@@ -51,3 +51,4 @@ changelog entry.
|
||||
- On X11, fix debug mode overflow panic in `set_timestamp`.
|
||||
- On macOS, fix crash in `set_marked_text` when native Pinyin IME sends out-of-bounds `selected_range`.
|
||||
- On Windows, fix `WM_IME_SETCONTEXT` IME UI flag masking on `lParam`.
|
||||
- On Android, populate `KeyEvent::text` and `KeyEvent::text_with_all_modifiers` via `Key::to_text()`
|
||||
|
||||
@@ -446,6 +446,13 @@ impl<T: 'static> EventLoop<T> {
|
||||
&mut self.combining_accent,
|
||||
);
|
||||
|
||||
let logical_key = keycodes::to_logical(key_char, keycode);
|
||||
let text = if state == event::ElementState::Pressed {
|
||||
logical_key.to_text().map(smol_str::SmolStr::new)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let event = event::Event::WindowEvent {
|
||||
window_id: window::WindowId(WindowId),
|
||||
event: event::WindowEvent::KeyboardInput {
|
||||
@@ -453,10 +460,10 @@ impl<T: 'static> EventLoop<T> {
|
||||
event: event::KeyEvent {
|
||||
state,
|
||||
physical_key: keycodes::to_physical_key(keycode),
|
||||
logical_key: keycodes::to_logical(key_char, keycode),
|
||||
logical_key,
|
||||
location: keycodes::to_location(keycode),
|
||||
repeat: key.repeat_count() > 0,
|
||||
text: None,
|
||||
text,
|
||||
platform_specific: KeyEventExtra {},
|
||||
},
|
||||
is_synthetic: false,
|
||||
|
||||
Reference in New Issue
Block a user