   return node.nextSibling
 
 
-# Return the next Node in a last-to-first-child pre-order traversal.
-preLast = (node) ->
+# Return the next Node in a reverse document order traversal.
+# This order is equivalent to pre-order with the child order reversed.
+documentReverse = (node) ->
   if node.lastChild?
     return node.lastChild
 

# The predicate function is invoked once for each Node in the tree.
# An optional third argument specifies a traversal order and should be a
# function that takes a Node and returns its successor. The default order is
# DOM position order (pre-order).
everyNode = (node, fn, next = preFirst) ->
  return !someNode(node, ((n) -> !fn(n)), next)


# Return the first Node in the tree that matches the predicate.
# An optional third argument specifies a traversal and should be a function
# that returns the successor of its argument. The default is document order.
findNode = (node, fn, next = preFirst) ->
  node = next(node) while node? and not result = fn(node)
  return (if result then node else undefined)



    if not contains(bounds, @start)
      node = bounds
      next = (node) -> node isnt last and documentForward(node) or null
      last = lastLeaf(bounds)
      node = next(node) while not isTextNode(node)
      @start = node

    if not contains(bounds, @end)
      node = bounds
      next = (node) -> node isnt last and documentReverse(node) or null
      last = firstLeaf(bounds)
      node = next(node) while not isTextNode(node)
      @end = node
