"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);
var unhangRange_exports = {};
__export(unhangRange_exports, {
  default: () => unhangRange_default
});
module.exports = __toCommonJS(unhangRange_exports);
var import_slate = require("slate");
function unhangRange(editor, range) {
  let [start, end] = import_slate.Range.edges(range);
  if (start.offset !== 0 || end.offset !== 0 || import_slate.Range.isCollapsed(range)) {
    return range;
  }
  const endBlock = import_slate.Editor.above(editor, {
    at: end,
    match: (n) => import_slate.Element.isElement(n) && import_slate.Editor.isBlock(editor, n)
  });
  const blockPath = endBlock ? endBlock[1] : [];
  const first = import_slate.Editor.start(editor, start);
  const before = { anchor: first, focus: end };
  let skip = true;
  for (const [node, path] of import_slate.Editor.nodes(editor, {
    at: before,
    match: import_slate.Text.isText,
    reverse: true
  })) {
    if (skip) {
      skip = false;
      continue;
    }
    if (node.text !== "" || import_slate.Path.isBefore(path, blockPath)) {
      end = { path, offset: node.text.length };
      break;
    }
  }
  return { anchor: start, focus: end };
}
var unhangRange_default = unhangRange;
//# sourceMappingURL=unhangRange.js.map