src/edit/dompos.js
// that position, relative to the window.
that position, relative to the window.
that position relative to the window .
function coordsAtPos(pm, pos) {
  let {node, offset} = DOMFromPos(pm.content, pos)
  let side, rect
  if (node.nodeType == 3) {
    if (offset < node.nodeValue.length) {
      rect = textRect(node, offset, offset + 1)
      side = "left"
    }
    if ((!rect || rect.left == rect.right) && offset) {
      rect = textRect(node, offset - 1, offset)
      side = "right"
    }
  } else if (node.firstChild) {
    if (offset < node.childNodes.length) {
      let child = node.childNodes[offset]
      rect = child.nodeType == 3 ? textRect(child, 0, child.nodeValue.length) : child.getBoundingClientRect()
      side = "left"
    }
    if ((!rect || rect.left == rect.right) && offset) {
      let child = node.childNodes[offset - 1]
      rect = child.nodeType == 3 ? textRect(child, 0, child.nodeValue.length) : child.getBoundingClientRect()
      side = "right"
    }
  } else {
    rect = node.getBoundingClientRect()
    side = "left"
  }
  let x = rect[side]
  return {top: rect.top, bottom: rect.bottom, left: x, right: x}
}
function coordsAtPos ( pm , pos ) { let { node , offset } = DOMFromPos ( pm . content , pos ) let side , rect if ( node . nodeType == 3 ) { if ( offset < node . nodeValue . length ) { rect = textRect ( node , offset , offset + 1 ) side = "left" } if ( ( ! rect || rect . left == rect . right ) && offset ) { rect = textRect ( node , offset - 1 , offset ) side = "right" } } else if ( node . firstChild ) { if ( offset < node . childNodes . length ) { let child = node . childNodes [ offset ] rect = child . nodeType == 3 ? textRect ( child , 0 , child . nodeValue . length ) : child . getBoundingClientRect ( ) side = "left" } if ( ( ! rect || rect . left == rect . right ) && offset ) { let child = node . childNodes [ offset - 1 ] rect = child . nodeType == 3 ? textRect ( child , 0 , child . nodeValue . length ) : child . getBoundingClientRect ( ) side = "right" } } else { rect = node . getBoundingClientRect ( ) side = "left" } let x = rect [ side ] return { top : rect . top , bottom : rect . bottom , left : x , right : x } }
that position, relative to the window.
that position relative to the window .