mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
CommandPanel commands can only be undone if they change the buffer
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user