Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

1.0 KB
Raw Blame
import type { Options } from 'react-hotkeys-hook';

/**
 * Adds the canvas text-session guard without converting a statically disabled hotkey into a mounted listener.
 *
 * react-hotkeys-hook does not attach its listener when `enabled` is exactly `false`. If `false` is wrapped in a
 * function instead, the listener remains attached and stops immediate propagation when the key matches. That can
 * prevent another, enabled handler for the same key from running.
 */
export const getRegisteredHotkeyOptions = (
  options: Options,
  isUncommittedCanvasTextSessionActive: () => boolean
): Options => {
  if (options.enabled === false) {
    return options;
  }

  const configuredEnabled = options.enabled;

  return {
    ...options,
    enabled: (event, hotkeysEvent) => {
      if (isUncommittedCanvasTextSessionActive()) {
        return false;
      }
      if (typeof configuredEnabled === 'function') {
        return configuredEnabled(event, hotkeysEvent);
      }
      return configuredEnabled ?? true;
    },
  };
};