       node = walker.currentNode
 
     if node.nodeType is Node.TEXT_NODE
-      [node, position - node.trixPosition]
+      container = node
+      offset = position - node.trixPosition
     else
-      offset = [node.parentNode.childNodes...].indexOf(node)
-      [node.parentNode, offset]
+      container = node.parentNode
+      offset =
+        if node.nextSibling
+          [node.parentNode.childNodes...].indexOf(node)
+        else
+          node.parentNode.childNodes.length
+
+    [container, offset]
 
   isWithin = (ancestor, element) ->
     while element

    if container.nodeType is Node.TEXT_NODE
      container.trixPosition + offset
    else
      container.childNodes[offset]?.trixPosition ? offset

  findContainerAndOffsetForPosition: (position) ->
    return [@element, 0] if position < 1

    @element.setAttribute("contenteditable", "true")
    @element.setAttribute("autocorrect", "off")
    @element.setAttribute("spellcheck", "false")
    @element.trixPosition = 0

  focus: ->
    @element.focus()
