MCPcopy Create free account
hub / github.com/anus-dev/ANUS / matchKeyBinding

Function matchKeyBinding

packages/cli/src/ui/keyMatchers.ts:20–59  ·  view source on GitHub ↗

* Matches a KeyBinding against an actual Key press * Pure data-driven matching logic

(keyBinding: KeyBinding, key: Key)

Source from the content-addressed store, hash-verified

18 * Pure data-driven matching logic
19 */
20function matchKeyBinding(keyBinding: KeyBinding, key: Key): boolean {
21 // Either key name or sequence must match (but not both should be defined)
22 let keyMatches = false;
23
24 if (keyBinding.key !== undefined) {
25 keyMatches = keyBinding.key === key.name;
26 } else if (keyBinding.sequence !== undefined) {
27 keyMatches = keyBinding.sequence === key.sequence;
28 } else {
29 // Neither key nor sequence defined - invalid binding
30 return false;
31 }
32
33 if (!keyMatches) {
34 return false;
35 }
36
37 // Check modifiers - follow original logic:
38 // undefined = ignore this modifier (original behavior)
39 // true = modifier must be pressed
40 // false = modifier must NOT be pressed
41
42 if (keyBinding.ctrl !== undefined && key.ctrl !== keyBinding.ctrl) {
43 return false;
44 }
45
46 if (keyBinding.shift !== undefined && key.shift !== keyBinding.shift) {
47 return false;
48 }
49
50 if (keyBinding.command !== undefined && key.meta !== keyBinding.command) {
51 return false;
52 }
53
54 if (keyBinding.paste !== undefined && key.paste !== keyBinding.paste) {
55 return false;
56 }
57
58 return true;
59}
60
61/**
62 * Checks if a key matches any of the bindings for a command

Callers 1

matchCommandFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected