* Matches a KeyBinding against an actual Key press * Pure data-driven matching logic
(keyBinding: KeyBinding, key: Key)
| 18 | * Pure data-driven matching logic |
| 19 | */ |
| 20 | function 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 |