CommandPanel commands can only be undone if they change the buffer

This commit is contained in:
Nathan Sobo
2012-12-04 13:38:18 -07:00
parent 4684bc5942
commit 9945c5ebbb
2 changed files with 18 additions and 1 deletions

View File

@@ -180,6 +180,16 @@ describe "CommandInterpreter", ->
runs ->
expect(editSession.getSelectedText()).toBe "y/b"
it "does not push to the undo stack (since the buffer is not modified)", ->
waitsForPromise ->
editSession.setSelectedBufferRange([[4,16], [4,20]])
interpreter.eval('/pivot/', editSession)
runs ->
selectedRangeBeforeUndo = editSession.getSelection().getBufferRange()
editSession.undo()
expect(editSession.getSelection().getBufferRange()).toEqual selectedRangeBeforeUndo
describe "when no match is found", ->
it "it returns an error messages", ->
errorMessages = null

View File

@@ -31,7 +31,7 @@ class CompositeCommand
bufferRanges = []
errorMessages = @errorMessagesForOperations(operations)
editSession.transact ->
executeOperations = ->
for operation in operations
bufferRange = operation.execute(editSession)
bufferRanges.push(bufferRange) if bufferRange
@@ -40,6 +40,13 @@ class CompositeCommand
if bufferRanges.length and not currentCommand.preserveSelections
editSession.setSelectedBufferRanges(bufferRanges, autoscroll: true)
operationsWillChangeBuffer = _.detect(operations, (operation) -> operation.newText)
if operationsWillChangeBuffer
editSession.transact(executeOperations)
else
executeOperations()
deferred.resolve({errorMessages})
deferred.promise()