   getNativeRange: (normalize = false) ->
     return null unless @nativeSelection
     @nativeSelection.refresh()
-    range = if @nativeSelection?.rangeCount > 0 then @nativeSelection.getRangeAt(0) else null
+    # Editor needs focus for us to consider valid range
+    return null unless @editor.root.ownerDocument.activeElement == @editor.root and @nativeSelection?.rangeCount > 0
+    range = @nativeSelection.getRangeAt(0)
+    # Selection elements needs to be within editor root
+    return null unless rangy.dom.isAncestorOf(@editor.root, range.startContainer) and rangy.dom.isAncestorOf(@editor.root, range.endContainer)
     range = normalizeNativeRange(range) if normalize
     range.isBackwards = true if @nativeSelection.isBackwards()
     return range

      fn.call(null)

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

  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)

