// packages/block-editor/src/components/rich-text/event-listeners/undo-automatic-change.js
import { BACKSPACE, ESCAPE } from "@wordpress/keycodes";
import { privateApis as composePrivateApis } from "@wordpress/compose";
import { store as blockEditorStore } from "../../../store/index.mjs";
import { unlock } from "../../../lock-unlock.mjs";
var { subscribeDelegatedListener } = unlock(composePrivateApis);
var undo_automatic_change_default = (props) => (element) => {
  function onKeyDown(event) {
    const { keyCode } = event;
    if (event.defaultPrevented) {
      return;
    }
    if (keyCode !== BACKSPACE && keyCode !== ESCAPE) {
      return;
    }
    const { registry } = props.current;
    const { didAutomaticChange, getSettings } = registry.select(blockEditorStore);
    const { __experimentalUndo } = getSettings();
    if (!__experimentalUndo) {
      return;
    }
    if (!didAutomaticChange()) {
      return;
    }
    event.preventDefault();
    __experimentalUndo();
  }
  return subscribeDelegatedListener(element, "keydown", onKeyDown);
};
export {
  undo_automatic_change_default as default
};
//# sourceMappingURL=undo-automatic-change.mjs.map
