mirror of
https://github.com/atom/atom.git
synced 2026-02-16 09:35:54 -05:00
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:
@@ -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()
|
||||
|
||||
@@ -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) ->
|
||||
|
||||
Reference in New Issue
Block a user