desktop: Fix doubling inputted characters

Fix a bug introduced by f65060e8.
The text input event was triggered two times: at key press and release.
This patch makes sure that text input is triggered only on key press.
This commit is contained in:
Kamil Jarosz 2024-01-17 21:44:00 +01:00 committed by TÖRÖK Attila
parent d153290fd6
commit d89ab3dc83
1 changed files with 5 additions and 12 deletions

View File

@ -312,7 +312,6 @@ impl App {
// [NA] TODO: This event used to give a single char. `last()` is functionally the same, // [NA] TODO: This event used to give a single char. `last()` is functionally the same,
// but we may want to be better at this in the future. // but we may want to be better at this in the future.
let key_char = event.text.clone().and_then(|text| text.chars().last()); let key_char = event.text.clone().and_then(|text| text.chars().last());
let mut allow_text = true;
match &event.state { match &event.state {
ElementState::Pressed => { ElementState::Pressed => {
@ -324,7 +323,11 @@ impl App {
self.player.handle_event(PlayerEvent::TextControl { self.player.handle_event(PlayerEvent::TextControl {
code: control_code, code: control_code,
}); });
allow_text = false; } else if let Some(text) = event.text {
for codepoint in text.chars() {
self.player
.handle_event(PlayerEvent::TextInput { codepoint });
}
} }
} }
ElementState::Released => { ElementState::Released => {
@ -333,16 +336,6 @@ impl App {
} }
}; };
check_redraw = true; check_redraw = true;
if allow_text {
if let Some(text) = event.text {
for codepoint in text.chars() {
self.player
.handle_event(PlayerEvent::TextInput { codepoint });
}
check_redraw = true;
}
}
} }
_ => (), _ => (),
} }