function getVisibleSelectionRect()

in src/component/selection/getVisibleSelectionRect.js [25:43]


function getVisibleSelectionRect(global: any): ?FakeClientRect {
  const selection = global.getSelection();
  if (!selection.rangeCount) {
    return null;
  }

  const range = selection.getRangeAt(0);
  const boundingRect = getRangeBoundingClientRect(range);
  const {top, right, bottom, left} = boundingRect;

  // When a re-render leads to a node being removed, the DOM selection will
  // temporarily be placed on an ancestor node, which leads to an invalid
  // bounding rect. Discard this state.
  if (top === 0 && right === 0 && bottom === 0 && left === 0) {
    return null;
  }

  return boundingRect;
}