// packages/rich-text/src/component/event-listeners/delete.js
import { BACKSPACE, DELETE } from "@wordpress/keycodes";
import { remove } from "../../remove.mjs";
var delete_default = (props) => (element) => {
  function onKeyDown(event) {
    const { keyCode } = event;
    const { createRecord, handleChange } = props.current;
    if (event.defaultPrevented) {
      return;
    }
    if (keyCode !== DELETE && keyCode !== BACKSPACE) {
      return;
    }
    const currentValue = createRecord();
    const { start, end, text } = currentValue;
    if (start === 0 && end !== 0 && end === text.length) {
      handleChange(remove(currentValue));
      event.preventDefault();
    }
  }
  element.addEventListener("keydown", onKeyDown);
  return () => {
    element.removeEventListener("keydown", onKeyDown);
  };
};
export {
  delete_default as default
};
//# sourceMappingURL=delete.mjs.map
