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

Don't notify observers of onDidChangeText after an empty transaction #230

Merged
merged 1 commit into from
May 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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