       node.textContent is Trix.ZERO_WIDTH_SPACE
     else
       nodeIsCursorTarget(node.firstChild)
+
+  nodeLength = (node) ->
+    if nodeIsCursorTarget(node)
+      0
+    else if node.length?
+      node.length
+    else
+      1
 
   getDOMSelection = ->
     selection = window.getSelection()


    [container, offset]

  findNodeForLocation: (location) ->
    node = null
    for offset, nodes of @getNodeRecords()[location.index]
      candidate = nodes[nodes.length - 1]
      break if offset > location.offset
      node = candidate
      break if offset is location.offset and nodeIsCursorTarget(node)
    node

  getLocationRangeAtPoint: ([clientX, clientY]) ->
    if document.caretPositionFromPoint

      for offset, nodes of offsets when node in nodes
        index = Number(index)
        offset = Number(offset)
        if container.nodeType is Node.TEXT_NODE
          offset += containerOffset unless nodeIsCursorTarget(node)
        else
          offset += 1 unless containerOffset is 0
        return {index, offset}

  findContainerAndOffsetForLocation: (location) ->
    [node, nodeOffset] = @findNodeAndOffsetForLocation(location)

    if node.nodeType is Node.TEXT_NODE
      container = node
      offset = location.offset - nodeOffset
    else
      container = node.parentNode
      offset =
