MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / resolveKeyFromEvent

Function resolveKeyFromEvent

packages/app-core/src/lib/keymaps.ts:1172–1186  ·  view source on GitHub ↗

* Resolve the binding key from a KeyboardEvent. * * Layout-aware: when `event.key` is a single printable ASCII char it * reflects what the active keyboard layout *typed* (Colemak/Dvorak * users want `Cmd+P` to fire on whichever physical key produces `p`, * not on the QWERTY-P position). Letters

(event: KeyboardEvent)

Source from the content-addressed store, hash-verified

1170 * `normalizeKeyName(event.key)`.
1171 */
1172function resolveKeyFromEvent(event: KeyboardEvent): string | null {
1173 if (isModifierKey(event.key)) return null;
1174 const k = event.key;
1175 // Skip the typed-char fast path for '+': it is the binding-string
1176 // separator, so emitting it would produce unparsable strings like
1177 // "Mod+Shift++". Fall through to physicalKeyFromCode (event.code
1178 // = "Equal" -> "=" for Shift+Cmd+=).
1179 if (k.length === 1 && k !== "+") {
1180 const cp = k.charCodeAt(0);
1181 if (cp > 0x20 && cp < 0x7f) {
1182 return k.toUpperCase();
1183 }
1184 }
1185 return physicalKeyFromCode(event.code);
1186}
1187
1188function normalizeKeyName(key: string): string | null {
1189 if (!key) return null;

Callers 2

shortcutBindingFromEventFunction · 0.85
sequenceTokenFromEventFunction · 0.85

Calls 2

isModifierKeyFunction · 0.85
physicalKeyFromCodeFunction · 0.85

Tested by

no test coverage detected