 
   constructor: (@quill, @options = {}) ->
     @lastRecorded = 0
+    @emittedDelta = null
     this.clear()
     this.initListeners()
 

    if @stack[source].length > 0
      change = @stack[source].pop()
      @lastRecorded = 0
      this._ignoreChanges( =>
        @quill.updateContents(change[source], 'user')
        index = this._getLastChangeIndex(change[source])
        @quill.setSelection(index, index)
      )
      @stack[dest].push(change)

  _ignoreChanges: (fn) ->
    oldIgnoringChanges = @ignoringChanges
    @ignoringChanges = true
    fn.call(this)
    @ignoringChanges = oldIgnoringChanges


module.exports = UndoManager

        return false
      )
    )
    @quill.on(@quill.constructor.events.TEXT_CHANGE, (delta, origin) =>
      if delta.isEqual(@emittedDelta)
        @emittedDelta = null
        return
      this.record(delta, @oldDelta)
      @oldDelta = @quill.getContents()
    )

