"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const index = require("../../ContemberEditor/index.cjs");
const Slate = require("slate");
const isInReferenceElement = require("../utils/isInReferenceElement.cjs");
const ElementWithReference = require("../elements/ElementWithReference.cjs");
const overrideInsertBreak = (editor, options) => {
  const { insertBreak } = editor;
  editor.insertBreak = () => {
    const closestBlockEntry = index.ContemberEditor.closestBlockEntry(editor);
    if (closestBlockEntry && ElementWithReference.isElementWithReference(closestBlockEntry[0])) {
      const selection = editor.selection;
      const [, closestBlockPath] = closestBlockEntry;
      const [referenceStart, referenceEnd] = Slate.Editor.edges(editor, closestBlockPath);
      if (!selection) {
        return;
      }
      return Slate.Editor.withoutNormalizing(editor, () => {
        Slate.Transforms.wrapNodes(editor, editor.createDefaultElement([]), {
          at: {
            anchor: referenceStart,
            focus: referenceEnd
          },
          match: (node) => Slate.Text.isText(node) || Slate.Element.isElement(node) && editor.isInline(node)
        });
        const relative = Slate.Path.relative(selection.focus.path, closestBlockPath);
        Slate.Transforms.splitNodes(editor, {
          // The zero should be the newly created default element.
          at: {
            path: [...closestBlockPath, 0, ...relative],
            offset: selection.focus.offset
          },
          always: true
        });
      });
    }
    if (isInReferenceElement.isInReferenceElement(editor)) {
      return;
    }
    return insertBreak();
  };
};
exports.overrideInsertBreak = overrideInsertBreak;
//# sourceMappingURL=overrideInsertBreak.cjs.map
