MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / routeKeyEvent

Function routeKeyEvent

packages/core/src/keybindings/manager.ts:654–693  ·  view source on GitHub ↗
(
  state: KeybindingManagerState<KeyContext<S>>,
  event: ZrevEvent,
  context: KeyContext<S>,
)

Source from the content-addressed store, hash-verified

652 * @returns New state and consumed flag
653 */
654export function routeKeyEvent<S>(
655 state: KeybindingManagerState<KeyContext<S>>,
656 event: ZrevEvent,
657 context: KeyContext<S>,
658): RouteKeyResult<KeyContext<S>> {
659 // Only handle key down events
660 if (event.kind !== "key" || event.action !== "down") {
661 return { nextState: state, consumed: false };
662 }
663
664 // Convert event to ParsedKey
665 const key: ParsedKey = { key: event.key, mods: modsFromBitmask(event.mods) };
666
667 // Match in current mode chain
668 const { nextChordState, result } = matchInModeChain(state, key, event.timeMs, context);
669
670 const nextState: KeybindingManagerState<KeyContext<S>> = Object.freeze({
671 ...state,
672 chordState: nextChordState,
673 });
674
675 if (result.kind === "matched") {
676 // Execute handler
677 try {
678 result.binding.handler(context);
679 } catch (e) {
680 // Return error to caller instead of logging
681 return { nextState, consumed: true, handlerError: e };
682 }
683 return { nextState, consumed: true };
684 }
685
686 if (result.kind === "pending") {
687 // Chord in progress, consume the key
688 return { nextState, consumed: true };
689 }
690
691 // No match
692 return { nextState, consumed: false };
693}
694
695// Re-export for convenience
696export { CHORD_TIMEOUT_MS };

Callers 5

manager.test.tsFile · 0.85
processEventBatchFunction · 0.85

Calls 2

modsFromBitmaskFunction · 0.85
matchInModeChainFunction · 0.85

Tested by

no test coverage detected