@@ -964,24 +964,28 @@ class TextBuffer
964964 # Public: Undo the last operation. If a transaction is in progress, aborts it.
965965 undo : ->
966966 if pop = @history .popUndoStack ()
967- @ emitMarkerLayersDidUpdateEvent =>
968- @ applyChange (change) for change in pop .patch .getChanges ()
969- @ restoreFromMarkerSnapshot (pop .snapshot )
970- @ emitMarkerChangeEvents (pop .snapshot )
971- @ emitDidChangeTextEvent (pop .patch )
972- true
967+ markerLayerUpdateEventWasDisabled = @ disableMarkerLayersDidUpdateEvent ()
968+ @ applyChange (change) for change in pop .patch .getChanges ()
969+ @ restoreFromMarkerSnapshot (pop .snapshot )
970+ @ enableMarkersLayersDidUpdateEvent ()
971+ @ emitMarkerChangeEvents (pop .snapshot )
972+ @ disableMarkerLayersDidUpdateEvent () if markerLayerUpdateEventWasDisabled
973+ @ emitDidChangeTextEvent (pop .patch )
974+ true
973975 else
974976 false
975977
976978 # Public: Redo the last operation
977979 redo : ->
978980 if pop = @history .popRedoStack ()
979- @ emitMarkerLayersDidUpdateEvent =>
980- @ applyChange (change) for change in pop .patch .getChanges ()
981- @ restoreFromMarkerSnapshot (pop .snapshot )
982- @ emitMarkerChangeEvents (pop .snapshot )
983- @ emitDidChangeTextEvent (pop .patch )
984- true
981+ markerLayerUpdateEventWasDisabled = @ disableMarkerLayersDidUpdateEvent ()
982+ @ applyChange (change) for change in pop .patch .getChanges ()
983+ @ restoreFromMarkerSnapshot (pop .snapshot )
984+ @ enableMarkersLayersDidUpdateEvent ()
985+ @ emitMarkerChangeEvents (pop .snapshot )
986+ @ disableMarkerLayersDidUpdateEvent () if markerLayerUpdateEventWasDisabled
987+ @ emitDidChangeTextEvent (pop .patch )
988+ true
985989 else
986990 false
987991
@@ -1003,28 +1007,30 @@ class TextBuffer
10031007 fn = groupingInterval
10041008 groupingInterval = 0
10051009
1006- @ emitMarkerLayersDidUpdateEvent =>
1007- checkpointBefore = @history .createCheckpoint (@ createMarkerSnapshot (), true )
1010+ markerLayerUpdateEventWasDisabled = @ disableMarkerLayersDidUpdateEvent ()
1011+ checkpointBefore = @history .createCheckpoint (@ createMarkerSnapshot (), true )
10081012
1009- try
1010- @transactCallDepth ++
1011- result = fn ()
1012- catch exception
1013- @ revertToCheckpoint (checkpointBefore, true )
1014- throw exception unless exception instanceof TransactionAbortedError
1015- return
1016- finally
1017- @transactCallDepth --
1018-
1019- endMarkerSnapshot = @ createMarkerSnapshot ()
1020- compactedChanges = @history .groupChangesSinceCheckpoint (checkpointBefore, endMarkerSnapshot, true )
1021- global .atom ? .assert compactedChanges, " groupChangesSinceCheckpoint() returned false." , (error ) =>
1022- error .metadata = {history : @history .toString ()}
1023- @history .applyGroupingInterval (groupingInterval)
1024- @history .enforceUndoStackSizeLimit ()
1025- @ emitMarkerChangeEvents (endMarkerSnapshot)
1026- @ emitDidChangeTextEvent (compactedChanges) if compactedChanges
1027- result
1013+ try
1014+ @transactCallDepth ++
1015+ result = fn ()
1016+ catch exception
1017+ @ revertToCheckpoint (checkpointBefore, true )
1018+ throw exception unless exception instanceof TransactionAbortedError
1019+ return
1020+ finally
1021+ @transactCallDepth --
1022+
1023+ endMarkerSnapshot = @ createMarkerSnapshot ()
1024+ compactedChanges = @history .groupChangesSinceCheckpoint (checkpointBefore, endMarkerSnapshot, true )
1025+ global .atom ? .assert compactedChanges, " groupChangesSinceCheckpoint() returned false." , (error ) =>
1026+ error .metadata = {history : @history .toString ()}
1027+ @history .applyGroupingInterval (groupingInterval)
1028+ @history .enforceUndoStackSizeLimit ()
1029+ @ enableMarkersLayersDidUpdateEvent ()
1030+ @ emitMarkerChangeEvents (endMarkerSnapshot)
1031+ @ disableMarkerLayersDidUpdateEvent () if markerLayerUpdateEventWasDisabled
1032+ @ emitDidChangeTextEvent (compactedChanges) if compactedChanges
1033+ result
10281034
10291035 abortTransaction : ->
10301036 throw new TransactionAbortedError (" Transaction aborted." )
@@ -1052,12 +1058,14 @@ class TextBuffer
10521058 # Returns a {Boolean} indicating whether the operation succeeded.
10531059 revertToCheckpoint : (checkpoint ) ->
10541060 if truncated = @history .truncateUndoStack (checkpoint)
1055- @ emitMarkerLayersDidUpdateEvent =>
1056- @ applyChange (change) for change in truncated .patch .getChanges ()
1057- @ restoreFromMarkerSnapshot (truncated .snapshot )
1058- @emitter .emit ' did-update-markers'
1059- @ emitDidChangeTextEvent (truncated .patch )
1060- true
1061+ markerLayerUpdateEventWasDisabled = @ disableMarkerLayersDidUpdateEvent ()
1062+ @ applyChange (change) for change in truncated .patch .getChanges ()
1063+ @ restoreFromMarkerSnapshot (truncated .snapshot )
1064+ @ enableMarkersLayersDidUpdateEvent ()
1065+ @ emitMarkerChangeEvents (truncated .snapshot )
1066+ @ disableMarkerLayersDidUpdateEvent () if markerLayerUpdateEventWasDisabled
1067+ @ emitDidChangeTextEvent (truncated .patch )
1068+ true
10611069 else
10621070 false
10631071
@@ -1547,20 +1555,20 @@ class TextBuffer
15471555
15481556 emitMarkerChangeEvents : (snapshot ) ->
15491557 for markerLayerId, markerLayer of @markerLayers
1558+ markerLayer .emitDidUpdateEvent ()
15501559 markerLayer .emitChangeEvents (snapshot? [markerLayerId])
15511560
1552- emitMarkerLayersDidUpdateEvent : ( fn ) ->
1561+ disableMarkerLayersDidUpdateEvent : ->
15531562 wasDisabled = @markerLayerDidUpdateEventDisabled
15541563 @markerLayerDidUpdateEventDisabled = true
15551564 for id, markerLayer of @markerLayers
15561565 markerLayer .setDisableDidUpdateEvent (true )
1557- result = fn ()
1558- @markerLayerDidUpdateEventDisabled = wasDisabled
1566+ wasDisabled
1567+
1568+ enableMarkersLayersDidUpdateEvent : ->
1569+ @markerLayerDidUpdateEventDisabled = false
15591570 for id, markerLayer of @markerLayers
15601571 markerLayer .setDisableDidUpdateEvent (false )
1561- markerLayer .emitDidUpdateEvent ()
1562- markerLayer .setDisableDidUpdateEvent (wasDisabled)
1563- result
15641572
15651573 emitDidChangeTextEvent : (patch ) ->
15661574 return if @transactCallDepth isnt 0
0 commit comments