macos: ignore alt key with other modifiers set

This enables shifted alt-prefixed keys, such as `shift+alt+.` on
US standard becoming `M->`. To do this, we needed to fix a few bugs:

  (1) translation mods should strip alt even if other mods are set
  (2) AppKit translation event needs to construct new characters with
      the translation mods.
  (3) Alt-prefix handling in KeyEncoder needs to allow ASCII utf8
      translations even for macOS.
This commit is contained in:
Mitchell Hashimoto
2023-11-13 19:08:20 -08:00
parent ae112f48b9
commit 35e78939e5
4 changed files with 35 additions and 28 deletions

View File

@@ -325,15 +325,6 @@ fn legacyAltPrefix(
.right => if (mods.sides.alt == .left) return null,
.true => {},
}
if (self.event.unshifted_codepoint > 0) {
if (std.math.cast(
u8,
self.event.unshifted_codepoint,
)) |byte| {
return byte;
}
}
}
// Otherwise, we require utf8 to already have the byte represented.
@@ -1241,6 +1232,25 @@ test "legacy: alt+x macos" {
try testing.expectEqualStrings("\x1Bc", actual);
}
test "legacy: shift+alt+. macos" {
if (comptime !builtin.target.isDarwin()) return error.SkipZigTest;
var buf: [128]u8 = undefined;
var enc: KeyEncoder = .{
.event = .{
.key = .period,
.utf8 = ">",
.unshifted_codepoint = '.',
.mods = .{ .alt = true, .shift = true },
},
.alt_esc_prefix = true,
.macos_option_as_alt = .true,
};
const actual = try enc.legacy(&buf);
try testing.expectEqualStrings("\x1B>", actual);
}
test "legacy: alt+ф" {
var buf: [128]u8 = undefined;
var enc: KeyEncoder = .{