mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Replace stayValid option w/ validationStrategy when creating markers
This commit is contained in:
@@ -861,8 +861,8 @@ describe 'Buffer', ->
|
||||
buffer.undo()
|
||||
expect(buffer.getMarkerRange(marker)).toBeUndefined()
|
||||
|
||||
# even "stayValid" markers get destroyed properly
|
||||
marker2 = buffer.markRange([[4, 20], [4, 23]], stayValid: true)
|
||||
# even "invalidationStrategy: never" markers get destroyed properly
|
||||
marker2 = buffer.markRange([[4, 20], [4, 23]], invalidationStrategy: 'never')
|
||||
buffer.delete([[4, 15], [4, 25]])
|
||||
buffer.destroyMarker(marker2)
|
||||
buffer.undo()
|
||||
@@ -873,7 +873,7 @@ describe 'Buffer', ->
|
||||
|
||||
beforeEach ->
|
||||
marker1 = buffer.markRange([[4, 20], [4, 23]])
|
||||
marker2 = buffer.markRange([[4, 20], [4, 23]], stayValid: true)
|
||||
marker2 = buffer.markRange([[4, 20], [4, 23]], invalidationStrategy: 'never')
|
||||
|
||||
describe "when the buffer changes due to a new operation", ->
|
||||
describe "when the change precedes the marker range", ->
|
||||
@@ -911,14 +911,14 @@ describe 'Buffer', ->
|
||||
expect(buffer.getMarkerRange(marker1)).toEqual [[4, 20], [4, 26]]
|
||||
|
||||
describe "when the change surrounds the marker range", ->
|
||||
describe "when the marker was created with stayValid: false (the default)", ->
|
||||
describe "when the marker's invalidation strategy is 'contains' (the default)", ->
|
||||
it "invalidates the marker", ->
|
||||
buffer.delete([[4, 15], [4, 25]])
|
||||
expect(buffer.getMarkerRange(marker1)).toBeUndefined()
|
||||
buffer.undo()
|
||||
expect(buffer.getMarkerRange(marker1)).toEqual [[4, 20], [4, 23]]
|
||||
|
||||
describe "when the marker was created with stayValid: true", ->
|
||||
describe "when the marker's invalidation strategy is 'never'", ->
|
||||
it "does not invalidate the marker, but sets it to an empty range at the end of the change", ->
|
||||
buffer.change([[4, 15], [4, 25]], "...")
|
||||
expect(buffer.getMarkerRange(marker2)).toEqual [[4, 18], [4, 18]]
|
||||
@@ -926,14 +926,14 @@ describe 'Buffer', ->
|
||||
expect(buffer.getMarkerRange(marker2)).toEqual [[4, 20], [4, 23]]
|
||||
|
||||
describe "when the change straddles the start of the marker range", ->
|
||||
describe "when the marker was created with stayValid: false (the default)", ->
|
||||
describe "when the marker's invalidation strategy is 'contains' (the default)", ->
|
||||
it "invalidates the marker", ->
|
||||
buffer.delete([[4, 15], [4, 22]])
|
||||
expect(buffer.getMarkerRange(marker1)).toBeUndefined()
|
||||
buffer.undo()
|
||||
expect(buffer.getMarkerRange(marker1)).toEqual [[4, 20], [4, 23]]
|
||||
|
||||
describe "when the marker was created with stayValid: true", ->
|
||||
describe "when the marker's invalidation strategy is 'never'", ->
|
||||
it "moves the start of the marker range to the end of the change", ->
|
||||
buffer.delete([[4, 15], [4, 22]])
|
||||
expect(buffer.getMarkerRange(marker2)).toEqual [[4, 15], [4, 16]]
|
||||
@@ -941,14 +941,14 @@ describe 'Buffer', ->
|
||||
expect(buffer.getMarkerRange(marker1)).toEqual [[4, 20], [4, 23]]
|
||||
|
||||
describe "when the change straddles the end of the marker range", ->
|
||||
describe "when the marker was created with stayValid: false (the default)", ->
|
||||
describe "when the marker's invalidation strategy is 'contains' (the default)", ->
|
||||
it "invalidates the marker", ->
|
||||
buffer.delete([[4, 22], [4, 25]])
|
||||
expect(buffer.getMarkerRange(marker1)).toBeUndefined()
|
||||
buffer.undo()
|
||||
expect(buffer.getMarkerRange(marker1)).toEqual [[4, 20], [4, 23]]
|
||||
|
||||
describe "when the marker was created with stayValid: true", ->
|
||||
describe "when the marker's invalidation strategy is 'never'", ->
|
||||
it "moves the end of the marker range to the start of the change", ->
|
||||
buffer.delete([[4, 22], [4, 25]])
|
||||
expect(buffer.getMarkerRange(marker2)).toEqual [[4, 20], [4, 22]]
|
||||
|
||||
@@ -8,9 +8,9 @@ class BufferMarker
|
||||
headPosition: null
|
||||
tailPosition: null
|
||||
suppressObserverNotification: false
|
||||
stayValid: false
|
||||
invalidationStrategy: 'contains'
|
||||
|
||||
constructor: ({@id, @buffer, range, @stayValid, noTail, reverse}) ->
|
||||
constructor: ({@id, @buffer, range, @invalidationStrategy, noTail, reverse}) ->
|
||||
@setRange(range, {noTail, reverse})
|
||||
|
||||
setRange: (range, options={}) ->
|
||||
@@ -76,7 +76,7 @@ class BufferMarker
|
||||
containsEnd = oldRange.containsPoint(@getEndPosition(), exclusive: true)
|
||||
return unless containsEnd or containsStart
|
||||
|
||||
if @stayValid
|
||||
if @invalidationStrategy is 'never'
|
||||
previousRange = @getRange()
|
||||
if containsStart and containsEnd
|
||||
@setRange([oldRange.end, oldRange.end])
|
||||
|
||||
@@ -538,11 +538,11 @@ class EditSession
|
||||
_.last(@cursors)
|
||||
|
||||
addCursorAtScreenPosition: (screenPosition) ->
|
||||
marker = @markScreenPosition(screenPosition, stayValid: true)
|
||||
marker = @markScreenPosition(screenPosition, invalidationStrategy: 'never')
|
||||
@addSelection(marker).cursor
|
||||
|
||||
addCursorAtBufferPosition: (bufferPosition) ->
|
||||
marker = @markBufferPosition(bufferPosition, stayValid: true)
|
||||
marker = @markBufferPosition(bufferPosition, invalidationStrategy: 'never')
|
||||
@addSelection(marker).cursor
|
||||
|
||||
addCursor: (marker) ->
|
||||
@@ -565,7 +565,7 @@ class EditSession
|
||||
selection
|
||||
|
||||
addSelectionForBufferRange: (bufferRange, options={}) ->
|
||||
options = _.defaults({stayValid: true}, options)
|
||||
options = _.defaults({invalidationStrategy: 'never'}, options)
|
||||
marker = @markBufferRange(bufferRange, options)
|
||||
@addSelection(marker)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user