 # Return true if the given predicate is true for any Node of the tree.
 # An optional third argument specifies a traversal and should be a function
 # that returns the successor of its argument. The default is document order.
-someNode = (node, fn, next = preFirst) ->
+someNode = (node, fn, next = documentForward) ->
   return !!findNode(node, fn, next)
 
 
 # Return an Array of each Node in the tree for which the predicate is true.
 # An optional third argument specifies a traversal and should be a function
 # that returns the successor of its argument. The default is document order.
-filterNode = (node, fn, next = preFirst) ->
+filterNode = (node, fn, next = documentForward) ->
   collect = (acc, n) -> if fn(n) then acc.concat([n]) else acc
   return reduceNode(node, collect, [], next)
 

# 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
