input: legacy encoding pc style keys should ignore directional modifiers

This commit is contained in:
Mitchell Hashimoto
2023-10-12 12:28:26 -07:00
parent f402ca140c
commit d97e5b9dab

View File

@ -319,7 +319,11 @@ fn pcStyleFunctionKey(
keypad_key_application: bool,
modify_other_keys: bool, // True if state 2
) ?[]const u8 {
const mods_int = mods.int();
// We only want binding-sensitive mods because lock keys
// and directional modifiers (left/right) don't matter for
// pc-style function keys.
const mods_int = mods.binding().int();
for (function_keys.keys.get(keyval)) |entry| {
switch (entry.cursor) {
.any => {},
@ -1328,6 +1332,38 @@ test "legacy: f1" {
}
}
test "legacy: left_shift+tab" {
var buf: [128]u8 = undefined;
var enc: KeyEncoder = .{
.event = .{
.key = .tab,
.mods = .{
.shift = true,
.sides = .{ .shift = .left },
},
},
};
const actual = try enc.legacy(&buf);
try testing.expectEqualStrings("\x1b[Z", actual);
}
test "legacy: right_shift+tab" {
var buf: [128]u8 = undefined;
var enc: KeyEncoder = .{
.event = .{
.key = .tab,
.mods = .{
.shift = true,
.sides = .{ .shift = .right },
},
},
};
const actual = try enc.legacy(&buf);
try testing.expectEqualStrings("\x1b[Z", actual);
}
test "ctrlseq: normal ctrl c" {
const seq = ctrlSeq(.c, .{ .ctrl = true });
try testing.expectEqual(@as(u8, 0x03), seq.?);