From 0c65cc1e0d632653f7c8baf16ae7831f2ab42e57 Mon Sep 17 00:00:00 2001 From: iceiix <43691553+iceiix@users.noreply.github.com> Date: Sat, 16 Jan 2021 14:11:17 -0800 Subject: [PATCH] ui: keyboard input fixes (#432, #476) (#477) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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. --- src/main.rs | 2 +- src/ui/mod.rs | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 34bf078..2615820 100644 --- a/src/main.rs +++ b/src/main.rs @@ -638,7 +638,7 @@ fn handle_window_event( } WindowEvent::ReceivedCharacter(codepoint) => { - if !game.focused { + if !game.focused && !game.is_ctrl_pressed && !game.is_logo_pressed { ui_container.key_type(game, codepoint); } } diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 4796c6d..88d51d4 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -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); }