From fda30fd528977a27f6dce497fa1fba6fc8c72f5f Mon Sep 17 00:00:00 2001 From: Philip Degarmo Date: Tue, 27 Aug 2019 21:50:33 -0700 Subject: [PATCH] Fix backspace for text entry fields. The original problem was that hitting backspace would insert 0x7f, and then delete it. This prevented deleting the intended character. --- imgui-winit-support/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/imgui-winit-support/src/lib.rs b/imgui-winit-support/src/lib.rs index b7f1c33..4b22297 100644 --- a/imgui-winit-support/src/lib.rs +++ b/imgui-winit-support/src/lib.rs @@ -313,7 +313,13 @@ impl WinitPlatform { _ => (), } } - WindowEvent::ReceivedCharacter(ch) => io.add_input_character(ch), + WindowEvent::ReceivedCharacter(ch) => { + // Exclude the backspace key ('\u{7f}'). Otherwise we will insert this char and then + // delete it. + if ch != '\u{7f}' { + io.add_input_character(ch) + } + } WindowEvent::CursorMoved { position, .. } => { let position = self.scale_pos_from_winit(window, position); io.mouse_pos = [position.x as f32, position.y as f32];