src/menu/tooltipmenu.js
// Get the x and y coordinates at the top center of the current DOM selection.
Get the x and y coordinates at the top center of the current DOM selection.
Get the x and y coordinates at the top center of the current DOM selection .
function topCenterOfSelection() {
  let range = window.getSelection().getRangeAt(0), rects = range.getClientRects()
  if (!rects.length) return range.getBoundingClientRect()
  let {left, right, top} = rects[0], i = 1
  while (left == right && rects.length > i) {
    ;({left, right, top} = rects[i++])
  }
  for (; i < rects.length; i++) {
    if (rects[i].top < rects[0].bottom - 1 &&
        (i == rects.length - 1 || Math.abs(rects[i + 1].left - rects[i].left) > 1)) {
      left = Math.min(left, rects[i].left)
      right = Math.max(right, rects[i].right)
      top = Math.min(top, rects[i].top)
    }
  }
  return {top, left: (left + right) / 2}
}
function topCenterOfSelection ( ) { let range = window . getSelection ( ) . getRangeAt ( 0 ) , rects = range . getClientRects ( ) if ( ! rects . length ) return range . getBoundingClientRect ( ) let { left , right , top } = rects [ 0 ] , i = 1 while ( left == right && rects . length > i ) { ; ( { left , right , top } = rects [ i ++ ] ) } for ( ; i < rects . length ; i ++ ) { if ( rects [ i ] . top < rects [ 0 ] . bottom - 1 && ( i == rects . length - 1 || Math . abs ( rects [ i + 1 ] . left - rects [ i ] . left ) > 1 ) ) { left = Math . min ( left , rects [ i ] . left ) right = Math . max ( right , rects [ i ] . right ) top = Math . min ( top , rects [ i ] . top ) } } return { top , left : ( left + right ) / 2 } }
Get the x and y coordinates at the top center of the current DOM selection.
Get the x and y coordinates at the top center of the current DOM selection .
// Chrome bug where bogus rectangles are inserted at span boundaries