From ecb1d19890b72cf1cd46979a01efb613ff2b8c03 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 29 Sep 2023 20:00:50 -0700 Subject: [PATCH] input: fix regression with ascii mapping to a keypad key --- src/Surface.zig | 2 +- src/input/key.zig | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Surface.zig b/src/Surface.zig index 587e166dc..298fb41e2 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -897,7 +897,7 @@ pub fn keyCallback( self: *Surface, event: input.KeyEvent, ) !bool { - // log.debug("keyCallback event={}", .{event}); + log.debug("keyCallback event={}", .{event}); // Before encoding, we see if we have any keybindings for this // key. Those always intercept before any encoding tasks. diff --git a/src/input/key.zig b/src/input/key.zig index aabd3e2e3..16aa2cd35 100644 --- a/src/input/key.zig +++ b/src/input/key.zig @@ -302,6 +302,9 @@ pub const Key = enum(c_int) { return comptime result: { @setEvalBranchQuota(100_000); for (codepoint_map) |entry| { + // No ASCII characters should ever map to a keypad key + if (entry[1].keypad()) continue; + if (entry[0] == @as(u21, @intCast(comptime_ch))) { break :result entry[1]; } @@ -357,6 +360,12 @@ pub const Key = enum(c_int) { }; } + test "fromASCII should not return keypad keys" { + const testing = std.testing; + try testing.expect(Key.fromASCII('0').? == .zero); + try testing.expect(Key.fromASCII('*') == null); + } + test "keypad keys" { const testing = std.testing; try testing.expect(Key.kp_0.keypad());