examples/ime: fix crash on wayland

When pressing Ctrl+Space, KeyEvent::text_with_all_modifiers would return
\0. That would get included in the text-input text. When an input method
gets activated, the invalid string returning \0 would get sent as
surrounding text, resulting in a Wayland protocol error and crashing the
application.
This commit is contained in:
DorotaC 2025-10-29 05:40:30 +01:00 committed by GitHub
parent bd6fef1d80
commit f41897cfa4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 3 deletions

View file

@ -788,9 +788,10 @@ pub struct KeyEvent {
/// ```
pub repeat: bool,
/// Similar to [`text`][Self::text], except that this is affected by <kbd>Ctrl</kbd>.
/// Similar to [`text`][Self::text], except that this is affected by <kbd>Ctrl</kbd> and may
/// produce ASCII control characters.
///
/// For example, pressing <kbd>Ctrl</kbd>+<kbd>a</kbd> produces `Some("\x01")`.
/// For example, pressing <kbd>Ctrl</kbd>+<kbd>space</kbd> produces `Some("\x00")`.
///
/// ## Platform-specific
///

View file

@ -200,7 +200,7 @@ impl App {
self.print_input_state();
},
_ => {
if let Some(text) = event.text_with_all_modifiers {
if let Some(text) = event.text {
self.input_state.append_text(&text);
if self.input_state.ime_enabled {
self.window()