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