ChemPal Documentation - v0.0.13-beta.5
    Preparing search index...

    Function matches

    • Checks whether a KeyboardEvent matches a ParsedBinding. Matching is strict on modifiers — any modifier that is not required in the binding must not be held down, so ctrl+s will not also fire for ctrl+shift+s. Key comparison is case-insensitive via event.key.

      Parameters

      Returns boolean

      true if the event matches the binding.

      const b = parseBinding("mod+shift+r");
      matches(event, b); // true when ⌘⇧R (mac) or Ctrl+Shift+R (other)
      export function matches(event: KeyboardEvent, binding: ParsedBinding): boolean {
      if (event.metaKey !== binding.meta) return false;
      if (event.ctrlKey !== binding.ctrl) return false;
      if (event.altKey !== binding.alt) return false;
      // `?` is produced by Shift+/ — event.key is already "?", so don't require shift
      // separately. For other keys, enforce the shift flag strictly.
      if (binding.key !== "?" && event.shiftKey !== binding.shift) return false;
      return event.key.toLowerCase() === binding.key.toLowerCase();
      }