Always restore marker ranges on undo/redo, even for valid markers

This commit is contained in:
Nathan Sobo 2013-05-01 17:32:39 -06:00
parent f48ee846e9
commit 988f4da6e1
3 changed files with 12 additions and 10 deletions

View File

@ -1027,6 +1027,13 @@ describe 'TextBuffer', ->
buffer.undo()
expect(marker1.getRange()).toEqual [[4, 23], [4, 26]]
it "restores the marker range exactly on undo", ->
marker = buffer.markRange([[3, 0], [3, 62]])
buffer.delete([[2, 0], [3, 0]])
expect(marker.getRange()).toEqual [[2, 0], [2, 62]]
buffer.undo()
expect(marker.getRange()).toEqual [[3, 0], [3, 62]]
describe "when the change follows the marker range", ->
it "does not move the marker", ->
buffer.insert([6, 5], '...')

View File

@ -100,7 +100,7 @@ class BufferChangeOperation
newRange
invalidateMarkers: (oldRange) ->
_.compact(@buffer.getMarkers().map (marker) -> marker.tryToInvalidate(oldRange))
@buffer.getMarkers().map (marker) -> marker.tryToInvalidate(oldRange)
pauseMarkerObservation: ->
marker.pauseEvents() for marker in @buffer.getMarkers(includeInvalid: true)

View File

@ -182,26 +182,21 @@ class BufferMarker
betweenStartAndEnd = @getRange().containsRange(changedRange, exclusive: false)
containsStart = changedRange.containsPoint(@getStartPosition(), exclusive: true)
containsEnd = changedRange.containsPoint(@getEndPosition(), exclusive: true)
previousRange = @getRange()
switch @invalidationStrategy
when 'between'
if betweenStartAndEnd or containsStart or containsEnd
@invalidate()
[@id]
@invalidate() if betweenStartAndEnd or containsStart or containsEnd
when 'contains'
if containsStart or containsEnd
@invalidate()
[@id]
@invalidate() if containsStart or containsEnd
when 'never'
if containsStart or containsEnd
previousRange = @getRange()
if containsStart and containsEnd
@setRange([changedRange.end, changedRange.end])
else if containsStart
@setRange([changedRange.end, @getEndPosition()])
else
@setRange([@getStartPosition(), changedRange.start])
[@id, previousRange]
[@id, previousRange]
handleBufferChange: (bufferChange) ->
@consolidateObserverNotifications true, =>