       fn.call(null)
 
   setRange: (range, silent = false) ->
-    return unless @nativeSelection? and @editor.root.ownerDocument.activeElement?.tagName != 'BODY'
-    @nativeSelection.removeAllRanges()
+    return unless @nativeSelection?
+    @nativeSelection.removeAllRanges() if @editor.root.ownerDocument.activeElement == @editor.root
     if range?
       nativeRange = rangy.createRangyRange()
       _.each([range.start, range.end], (pos, i) ->

  getNativeRange: (normalize = false) ->
    return null unless @nativeSelection
    @nativeSelection.refresh()
    range = if @nativeSelection?.rangeCount > 0 then @nativeSelection.getRangeAt(0) else null
    range = normalizeNativeRange(range) if normalize
    range.isBackwards = true if @nativeSelection.isBackwards()
    return range

  update: (silent = false) ->
    return if (@mouseIsDown or @keyIsDown) and !silent
    nativeRange = this.getNativeRange(false)
    unless nativeRange == @range or (nativeRange? and @range? and nativeRange.equals(@range))
      nativeRange = normalizeNativeRange(nativeRange)
      this.setRange(_nativeRangeToRange.call(this, nativeRange), silent)

