this repo has no description
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(matchText): uppercase target codepoint if shift or caps

Check if the target mods have shift or caps lock, and uppercase our
codepoint if they do. Someday we will need to allocate zg.case_data to
handle all of unicode casing, but for now we handle ascii until we
figure out a nice way to plumb in case_data.

+14 -1
+14 -1
src/Key.zig
··· 105 105 self_mods.shift = false; 106 106 self_mods.caps_lock = false; 107 107 var arg_mods = mods; 108 + 109 + // TODO: Use zg case_data for full unicode support. We'll need to allocate the case data 110 + // somewhere 111 + const _cp: u21 = if (cp < 128 and (mods.shift or mods.caps_lock)) 112 + // Uppercase our codepoint 113 + std.ascii.toUpper(@intCast(cp)) 114 + else 115 + cp; 116 + 108 117 arg_mods.num_lock = false; 109 118 arg_mods.shift = false; 110 119 arg_mods.caps_lock = false; 111 120 112 121 var buf: [4]u8 = undefined; 113 - const n = std.unicode.utf8Encode(cp, buf[0..]) catch return false; 122 + const n = std.unicode.utf8Encode(_cp, &buf) catch return false; 114 123 return std.mem.eql(u8, self.text.?, buf[0..n]) and std.meta.eql(self_mods, arg_mods); 115 124 } 116 125 ··· 388 397 const key: Key = .{ 389 398 .codepoint = 'a', 390 399 .mods = .{ .num_lock = true }, 400 + .text = "a", 391 401 }; 392 402 try testing.expect(key.matches('a', .{})); 403 + try testing.expect(!key.matches('a', .{ .shift = true })); 393 404 } 394 405 395 406 test "matches 'shift+a'" { 396 407 const key: Key = .{ 397 408 .codepoint = 'a', 409 + .shifted_codepoint = 'A', 398 410 .mods = .{ .shift = true }, 399 411 .text = "A", 400 412 }; 401 413 try testing.expect(key.matches('a', .{ .shift = true })); 414 + try testing.expect(!key.matches('a', .{})); 402 415 try testing.expect(key.matches('A', .{})); 403 416 try testing.expect(!key.matches('A', .{ .ctrl = true })); 404 417 }