     )
 
   setRange: (@range, silent = false) ->
-    rangySel = rangy.getSelection(@editor.contentWindow)
+    @nativeSelection.removeAllRanges()
     if @range?
-      rangySelRange = @range.getRangy()
-      rangySel.setSingleRange(rangySelRange)
-    else
-      rangySel.removeAllRanges()
+      nativeRange = @editor.root.ownerDocument.createRange()
+      [startNode, startOffset] = Scribe.DOM.findDeepestNode(@range.start.leafNode, @range.start.offset)
+      nativeRange.setStart(startNode, startOffset)
+      [endNode, endOffset] = Scribe.DOM.findDeepestNode(@range.end.leafNode, @range.end.offset)
+      nativeRange.setEnd(endNode, endOffset)
+      @nativeSelection.addRange(nativeRange)
     @editor.emit(Scribe.Editor.events.SELECTION_CHANGE, @range) unless silent
-
-  setRangeNative: (nativeSel) ->
-    rangySel = rangy.getSelection(@editor.contentWindow)
-    range = rangy.createRangyRange(@editor.contentWindow)
-    range.setStart(nativeSel.anchorNode, nativeSel.anchorOffset)
-    range.setEnd(nativeSel.focusNode, nativeSel.focusOffset)
-    rangySel.setSingleRange(range)
 
   update: (silent = false) ->
     range = this.getRange()

    this.update()
    return @range

  getNative: ->
    rangySel = rangy.getSelection(@editor.contentWindow)
    selection = window.getSelection()
    return null unless rangySel.anchorNode? and rangySel.focusNode? and @editor.root.contains(rangySel.anchorNode) and @editor.root.contains(rangySel.focusNode)
    if !rangySel.isBackwards()
      [anchorNode, anchorOffset, focusNode, focusOffset] = [rangySel.anchorNode, rangySel.anchorOffset, rangySel.focusNode, rangySel.focusOffset]
    else
      [focusNode, focusOffset, anchorNode, anchorOffset] = [rangySel.anchorNode, rangySel.anchorOffset, rangySel.focusNode, rangySel.focusOffset]
    return {
      anchorNode    : anchorNode
      anchorOffset  : anchorOffset
      focusNode     : focusNode
      focusOffset   : focusOffset
    }

  getRange: ->
    nativeSel = this.getNative()
    return null unless nativeSel?
    start = new Scribe.Position(@editor, nativeSel.anchorNode, nativeSel.anchorOffset)
    end = new Scribe.Position(@editor, nativeSel.focusNode, nativeSel.focusOffset)
    return new Scribe.Range(@editor, start, end)

  preserve: (fn) ->
    this.update(true)


  constructor: (@editor) ->
    @range = null
    @nativeSelection = @editor.contentWindow.getSelection()
    this.initListeners()

  initListeners: ->
