     name = "IndexSizeError"
     throw new DOMException(message, name)
 
-  start = findBoundary(startPath, startOffset)
-  end = findBoundary(endPath, endOffset)
+  start = findBoundary(startPath, startOffset, false)
+  end = findBoundary(endPath, endOffset, true)
 
   range.setStart(start.container, start.offset)
   range.setEnd(end.container, end.offset)

    textNodes = filterNode(origParent, isTextNode)

    # Calculate real offset as the combined length of all the
    # preceding textNode siblings. We include the length of the
    # node if it's the end node.
    nodes = textNodes.slice(0, textNodes.indexOf(node))
    offset = 0
    for n in nodes
      offset += n.nodeValue.length

    if isEnd then [path, offset + node.nodeValue.length] else [path, offset]

  start = serialization(range.startContainer)
  end   = serialization(range.endContainer, true)

    # process each TextNode until their combined length exceeds or matches the
    # value of the offset.
    for tn in filterNode(node, isTextNode)
      if (isEnd and tn.length == offset) or (offset < tn.length)
        return {container: tn, offset: offset}
      else
        offset -= tn.length
