Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #230 from atom/as-no-textchange-events-for-empty-t…
Browse files Browse the repository at this point in the history
…ransactions

Don't notify observers of `onDidChangeText` after an empty transaction
  • Loading branch information
Antonio Scandurra authored May 8, 2017
2 parents fc24cf4 + fc4b77a commit b73191c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 6 additions & 1 deletion spec/text-buffer-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2650,7 +2650,6 @@ describe "TextBuffer", ->
buffer.insert([2, 3], "zw")
buffer.delete([[2, 3], [2, 4]])


assertChangesEqual(textChanges, [
{
oldRange: [[1, 0], [1, 0]],
Expand Down Expand Up @@ -2715,6 +2714,12 @@ describe "TextBuffer", ->
}
])

it "doesn't notify observers after an empty transaction", ->
didChangeTextSpy = jasmine.createSpy()
buffer.onDidChangeText(didChangeTextSpy)
buffer.transact(->)
expect(didChangeTextSpy).not.toHaveBeenCalled()

it "doesn't throw an error when clearing the undo stack within a transaction", ->
buffer.onDidChangeText(didChangeTextSpy = jasmine.createSpy())
expect(-> buffer.transact(-> buffer.clearUndoStack())).not.toThrowError()
Expand Down
8 changes: 5 additions & 3 deletions src/text-buffer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1654,9 +1654,11 @@ class TextBuffer
emitDidChangeTextEvent: (patch) ->
return if @transactCallDepth isnt 0

@emitter.emit 'did-change-text', {changes: Object.freeze(normalizePatchChanges(patch.getHunks()))}
@patchesSinceLastStoppedChangingEvent.push(patch)
@scheduleDidStopChangingEvent()
hunks = patch.getHunks()
if hunks.length > 0
@emitter.emit 'did-change-text', {changes: Object.freeze(normalizePatchChanges(hunks))}
@patchesSinceLastStoppedChangingEvent.push(patch)
@scheduleDidStopChangingEvent()

# Identifies if the buffer belongs to multiple editors.
#
Expand Down

0 comments on commit b73191c

Please sign in to comment.