Skip to content

Commit

Permalink
desktop: Fix doubling inputted characters
Browse files Browse the repository at this point in the history
Fix a bug introduced by f65060e.
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.
  • Loading branch information
kjarosh authored and torokati44 committed Jan 17, 2024
1 parent d153290 commit d89ab3d
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions desktop/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ impl App {
// [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.
let key_char = event.text.clone().and_then(|text| text.chars().last());
let mut allow_text = true;

match &event.state {
ElementState::Pressed => {
Expand All @@ -324,7 +323,11 @@ impl App {
self.player.handle_event(PlayerEvent::TextControl {
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 => {
Expand All @@ -333,16 +336,6 @@ impl App {
}
};
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;
}
}
}
_ => (),
}
Expand Down

0 comments on commit d89ab3d

Please sign in to comment.