Hold marker [in]validation events until after buffer change events

For a while, the goal has been to prevent marker update events from
firing until after the buffer change event. But at the same time, we
want all the markers to be updated when the buffer change fires. This
commit irons out some issues for markers that are invalidated or
revalidated by the change, making their behavior consistent with the
rest of marker updates.
This commit is contained in:
Nathan Sobo
2013-04-30 17:37:28 -06:00
parent 40512a4823
commit 9aec992693
3 changed files with 108 additions and 43 deletions

View File

@@ -19,19 +19,21 @@ class BufferChangeOperation
@options ?= {}
do: ->
@pauseMarkerObservation()
@oldText = @buffer.getTextInRange(@oldRange)
@newRange = @calculateNewRange(@oldRange, @newText)
@markersToRestoreOnUndo = @invalidateMarkers(@oldRange)
@changeBuffer
newRange = @changeBuffer
oldRange: @oldRange
newRange: @newRange
oldText: @oldText
newText: @newText
redo: ->
@restoreMarkers(@markersToRestoreOnRedo)
@restoreMarkers(@markersToRestoreOnRedo) if @markersToRestoreOnRedo
@resumeMarkerObservation()
newRange
undo: ->
@pauseMarkerObservation()
@markersToRestoreOnRedo = @invalidateMarkers(@newRange)
@changeBuffer
oldRange: @newRange
@@ -39,6 +41,7 @@ class BufferChangeOperation
oldText: @newText
newText: @oldText
@restoreMarkers(@markersToRestoreOnUndo)
@resumeMarkerObservation()
splitLines: (text) ->
lines = text.split('\n')
@@ -74,13 +77,10 @@ class BufferChangeOperation
@buffer.cachedMemoryContents = null
@buffer.conflict = false if @buffer.conflict and !@buffer.isModified()
@pauseMarkerObservation()
event = { oldRange, newRange, oldText, newText }
@updateMarkers(event)
@buffer.trigger 'changed', event
@buffer.scheduleModifiedEvents()
@resumeMarkerObservation()
@buffer.trigger 'markers-updated'
newRange
@@ -99,10 +99,11 @@ class BufferChangeOperation
_.compact(@buffer.getMarkers().map (marker) -> marker.tryToInvalidate(oldRange))
pauseMarkerObservation: ->
marker.pauseEvents() for marker in @buffer.getMarkers()
marker.pauseEvents() for marker in @buffer.getMarkers(includeInvalid: true)
resumeMarkerObservation: ->
marker.resumeEvents() for marker in @buffer.getMarkers()
marker.resumeEvents() for marker in @buffer.getMarkers(includeInvalid: true)
@buffer.trigger 'markers-updated'
updateMarkers: (bufferChange) ->
marker.handleBufferChange(bufferChange) for marker in @buffer.getMarkers()

View File

@@ -425,8 +425,12 @@ class Buffer
isEmpty: -> @lines.length is 1 and @lines[0].length is 0
# Returns all valid {BufferMarker}s on the buffer.
getMarkers: ->
_.values(@validMarkers)
getMarkers: ({includeInvalid} = {}) ->
markers = _.values(@validMarkers)
if includeInvalid
markers.concat(_.values(@invalidMarkers))
else
markers
# Returns the {BufferMarker} with the given id.
getMarker: (id) ->