input: fix regression with ascii mapping to a keypad key

This commit is contained in:
Mitchell Hashimoto
2023-09-29 20:00:50 -07:00
parent d90aba20fe
commit ecb1d19890
2 changed files with 10 additions and 1 deletions

View File

@ -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.

View File

@ -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());