Allow Editor::batchUpdates calls to be nested

This commit is contained in:
Nathan Sobo
2014-06-02 17:48:40 +09:00
parent 1cc5ef3479
commit 03463da729

View File

@@ -144,6 +144,7 @@ class Editor extends Model
cursors: null
selections: null
suppressSelectionMerging: false
updateBatchDepth: 0
@delegatesMethods 'suggestedIndentForBufferRow', 'autoIndentBufferRow', 'autoIndentBufferRows',
'autoDecreaseIndentForBufferRow', 'toggleLineCommentForBufferRow', 'toggleLineCommentsForBufferRows',
@@ -1842,9 +1843,11 @@ class Editor extends Model
abortTransaction: -> @buffer.abortTransaction()
batchUpdates: (fn) ->
@emit 'batched-updates-started'
@emit 'batched-updates-started' if @updateBatchDepth is 0
@updateBatchDepth++
result = fn()
@emit 'batched-updates-ended'
@updateBatchDepth--
@emit 'batched-updates-ended' if @updateBatchDepth is 0
result
inspect: ->