ui: keyboard input fixes (#432, #476) (#477)

* Fix Cmd-V typing v, suppress key_type on ctrl/logo, closes #432
Only send key_type() when modifiers are not pressed.

* Fix backspace repeat and inserting ⌂, closes #476
Handle backspace in key_type instead of key_press, so we get
auto-repeat for free, and can suppress typing the character.
This commit is contained in:
iceiix 2021-01-16 14:11:17 -08:00 committed by GitHub
parent 4dd25de709
commit 0c65cc1e0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -638,7 +638,7 @@ fn handle_window_event<T>(
}
WindowEvent::ReceivedCharacter(codepoint) => {
if !game.focused {
if !game.focused && !game.is_ctrl_pressed && !game.is_logo_pressed {
ui_container.key_type(game, codepoint);
}
}

View File

@ -1537,9 +1537,6 @@ impl UIElement for TextBox {
ctrl_pressed: bool,
) {
match (key, down) {
(VirtualKeyCode::Back, _) => {
self.input.pop();
}
(VirtualKeyCode::Return, false) => {
use std::mem;
let len = self.submit_funcs.len();
@ -1564,6 +1561,12 @@ impl UIElement for TextBox {
}
fn key_type(&mut self, _game: &mut crate::Game, c: char) {
if c == '\x7f' || c == '\x08' {
// Backspace
self.input.pop();
return;
}
self.input.push(c);
}