// packages/block-editor/src/components/rich-text/shortcut.js
import { isKeyboardEvent } from "@wordpress/keycodes";
import { useEffect, useContext, useRef } from "@wordpress/element";
import { keyboardShortcutContext } from "./";
function RichTextShortcut({ character, type, onUse }) {
  const keyboardShortcuts = useContext(keyboardShortcutContext);
  const onUseRef = useRef();
  onUseRef.current = onUse;
  useEffect(() => {
    function callback(event) {
      if (isKeyboardEvent[type](event, character)) {
        onUseRef.current();
        event.preventDefault();
      }
    }
    keyboardShortcuts.current.add(callback);
    return () => {
      keyboardShortcuts.current.delete(callback);
    };
  }, [character, type]);
  return null;
}
export {
  RichTextShortcut
};
//# sourceMappingURL=shortcut.js.map
