 
     document = bounds.ownerDocument
 
+    first = firstLeaf(bounds)
+    last = lastLeaf(bounds)
+
     if not contains(bounds, @start)
-      @start = findNode(firstLeaf(bounds), bounds, isTextNode, postFirst)
+      @start = findNode(bounds, last, isTextNode, preFirst)
 
     if not contains(bounds, @end)
-      @end = findNode(lastLeaf(bounds), bounds, isTextNode, postLast)
+      @end = findNode(bounds, first, isTextNode, preLast)
 
     return null unless @start and @end
 

# Get all the text Nodes within a Node.
getTextNodes = (root) ->
  text = []
  node = firstLeaf(root)
  while node = findNode(node, root, isTextNode, postFirst)
    text.push(node)
    if node is root then break
    node = postFirst(node)
  return text



      endContainer = firstLeaf(endContainer.childNodes[endOffset])
      endOffset = 0

    # The above implies that a pre-order traversal visits every Node in the
    # Range before visiting the last leaf of the end container.
    first = firstLeaf(startContainer)

    # Similarly, a pre-order traversal that reverses the children visits every
    # Node in the Range before visiting the first leaf of the start container.
    last = lastLeaf(endContainer)

    # Any TextNode in the traversal is valid unless excluded by the offset.
    checkNode = (node) ->
