       @undoStack.push(patch)
     @clearRedoStack()
 
+  # Public: Undoes the last operation. If a transaction is in progress, aborts it.
   undo: ->
     if @currentTransaction?
       @abortTransaction()

      @redoStack.push(inverse)
      inverse.applyTo(@buffer)

  redo: ->
    if patch = @redoStack.pop()
      inverse = patch.invert(@buffer)
      @undoStack.push(inverse)
      inverse.applyTo(@buffer)

  transact: (fn) ->
    @beginTransaction()
    try

    else
      throw TransactionAborted

  # Public: Returns whether the buffer is currently in a transaction.
  isTransacting: ->
    @currentTransaction?

  # Public: Clears the undo stack
  clearUndoStack: ->
    @undoStack.length = 0

  # Public: Clears the redo stack
  clearRedoStack: ->
    @redoStack.length = 0
