 
   setRange: (range, silent = false) ->
     return unless @nativeSelection?
-    unless silent
-      # If we are not emitting change, we don't care what the cursor was
-      this.update(true) unless silent
-      return if range == @range or @range?.equals(range)
-    @range = range
-    if @range?
+    if range?
       nativeRange = rangy.createRangyRange()
-      _.each([@range.start, @range.end], (pos, i) ->
+      _.each([range.start, range.end], (pos, i) ->
         [node, offset] = Scribe.DOM.findDeepestNode(pos.leafNode, pos.offset)
         node = node.parentNode if node.tagName == "BR"              # Firefox does not like selections inside break tags
         offset = Math.min(Scribe.DOM.getText(node).length, offset)  # Should only occur at end of document

Scribe = require('./scribe')


# DOM Selection API says offset is child index of container, not number of characters like Scribe.Position
normalizeNativePosition = (node, offset) ->

      @nativeSelection.setSingleRange(nativeRange)
    else
      @nativeSelection.removeAllRanges()
    @editor.emit(Scribe.Editor.events.SELECTION_CHANGE, range) unless silent or range == @range or @range?.equals(range)
    @range = range

  update: (silent = false) ->
    nativeRange = normalizeNativeRange(this.getNativeRange())
    unless compareRanges(nativeRange, @range)
      this.setRange(_nativeRangeToRange.call(this, nativeRange), silent)


module.exports = Scribe
