"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/block-editor/src/components/rich-text/event-listeners/undo-automatic-change.js
var undo_automatic_change_exports = {};
__export(undo_automatic_change_exports, {
  default: () => undo_automatic_change_default
});
module.exports = __toCommonJS(undo_automatic_change_exports);
var import_keycodes = require("@wordpress/keycodes");
var import_store = require("../../../store");
var undo_automatic_change_default = (props) => (element) => {
  function onKeyDown(event) {
    const { keyCode } = event;
    if (event.defaultPrevented) {
      return;
    }
    if (keyCode !== import_keycodes.BACKSPACE && keyCode !== import_keycodes.ESCAPE) {
      return;
    }
    const { registry } = props.current;
    const { didAutomaticChange, getSettings } = registry.select(import_store.store);
    const { __experimentalUndo } = getSettings();
    if (!__experimentalUndo) {
      return;
    }
    if (!didAutomaticChange()) {
      return;
    }
    event.preventDefault();
    __experimentalUndo();
  }
  element.addEventListener("keydown", onKeyDown);
  return () => {
    element.removeEventListener("keydown", onKeyDown);
  };
};
//# sourceMappingURL=undo-automatic-change.js.map
