 #= require trix/utilities/dom
 #= require trix/utilities/helpers
 
+{DOM} = Trix
 {memoize} = Trix.Helpers
 
 class Trix.SelectionManager


  rangeWithinElement: (range) ->
    if range.collapsed
      Trix.DOM.within(@element, range.startContainer)
    else
      Trix.DOM.within(@element, range.startContainer) and Trix.DOM.within(@element, range.endContainer)

  findLocationFromContainerAtOffset: (container, offset) ->
    if container.nodeType is Node.TEXT_NODE

    [container, offset]

  findNodeForLocationRange: (range) ->
    walker = DOM.createTreeWalker(@element, null, nodeFilterForLocationRange)
    node = walker.currentNode

    while walker.nextNode()
