Merge pull request #1651 from aca/korean-esc

input: escape can be used to clear dead key state
This commit is contained in:
Mitchell Hashimoto
2024-04-04 22:18:09 -07:00
committed by GitHub

View File

@ -254,10 +254,19 @@ fn legacy(
self.ignore_keypad_with_numlock,
self.modify_other_keys_state_2,
)) |sequence| pc_style: {
// If we're pressing enter and have UTF-8 text, we probably are
// clearing a dead key state. This happens specifically on macOS.
// If we're pressing enter or escape and have UTF-8 text, we probably
// are clearing a dead key state. This happens specifically on macOS.
// "Clearing" a dead key state may or may not commit the dead key
// state; this differs by language:
//
// - Japanese clears and does not write the characters.
// - Korean clears and writes the characters.
//
// We have a unit test for this.
if (self.event.key == .enter and self.event.utf8.len > 0) {
if ((self.event.key == .enter or
self.event.key == .escape) and
self.event.utf8.len > 0)
{
break :pc_style;
}
@ -1649,6 +1658,20 @@ test "legacy: enter with utf8 (dead key state)" {
try testing.expectEqualStrings("A", actual);
}
test "legacy: esc with utf8 (dead key state)" {
var buf: [128]u8 = undefined;
var enc: KeyEncoder = .{
.event = .{
.key = .escape,
.utf8 = "A",
.unshifted_codepoint = 0x0D,
},
};
const actual = try enc.legacy(&buf);
try testing.expectEqualStrings("A", actual);
}
test "legacy: ctrl+shift+minus (underscore on US)" {
var buf: [128]u8 = undefined;
var enc: KeyEncoder = .{