Allow buffer marker head and tail positions to be manipulated

This commit is contained in:
Nathan Sobo
2013-01-30 22:13:50 -07:00
parent 5dd142b966
commit 1d1c613f5b
3 changed files with 38 additions and 13 deletions

View File

@@ -686,6 +686,25 @@ describe 'Buffer', ->
expect(buffer.getMarkerHeadPosition(marker)).toEqual [4, 20]
expect(buffer.getMarkerTailPosition(marker)).toEqual [4, 23]
describe "marker manipulation", ->
marker = null
beforeEach ->
marker = buffer.markRange([[4, 20], [4, 23]])
it "allows a markers head and tail positions to be changed", ->
buffer.setMarkerHeadPosition(marker, [5, 3])
expect(buffer.getMarkerRange(marker)).toEqual [[4, 20], [5, 3]]
buffer.setMarkerTailPosition(marker, [6, 3])
expect(buffer.getMarkerRange(marker)).toEqual [[5, 3], [6, 3]]
expect(buffer.isMarkerReversed(marker)).toBeTruthy()
it "clips head and tail positions to ensure they are in bounds", ->
buffer.setMarkerHeadPosition(marker, [-100, -5])
expect(buffer.getMarkerRange(marker)).toEqual([[0, 0], [4, 20]])
buffer.setMarkerTailPosition(marker, [Infinity, Infinity])
expect(buffer.getMarkerRange(marker)).toEqual([[0, 0], [12, 2]])
describe "marker updates due to buffer changes", ->
[marker1, marker2] = []

View File

@@ -33,6 +33,14 @@ class BufferMarker
getTailPosition: -> @tailPosition
setHeadPosition: (headPosition, options={}) ->
@headPosition = Point.fromObject(headPosition)
@headPosition = @buffer.clipPosition(@headPosition) if options.clip ? true
setTailPosition: (tailPosition, options={}) ->
@tailPosition = Point.fromObject(tailPosition)
@tailPosition = @buffer.clipPosition(@tailPosition) if options.clip ? true
getStartPosition: ->
@getRange().start
@@ -79,17 +87,6 @@ class BufferMarker
[newRow, newColumn]
setTailPosition: (tailPosition, options={}) ->
@tailPosition = Point.fromObject(tailPosition)
@tailPosition = @buffer.clipPosition(@tailPosition) if options.clip ? true
setHeadPosition: (headPosition, options={}) ->
@headPosition = Point.fromObject(headPosition)
@headPosition = @buffer.clipPosition(@headPosition) if options.clip ? true
getPosition: ->
@position
invalidate: (preserve) ->
delete @buffer.validMarkers[@id]
@buffer.invalidMarkers[@id] = this

View File

@@ -283,15 +283,24 @@ class Buffer
markPosition: (position, options) ->
@markRange([position, position], _.defaults({noTail: true}, options))
getMarkerPosition: (id) ->
@getMarkerHeadPosition(id)
getMarkerPosition: (args...) ->
@getMarkerHeadPosition(args...)
setMarkerPosition: (args...) ->
@setMarkerHeadPosition(args...)
getMarkerHeadPosition: (id) ->
@validMarkers[id]?.getHeadPosition()
setMarkerHeadPosition: (id, position, options) ->
@validMarkers[id]?.setHeadPosition(position)
getMarkerTailPosition: (id) ->
@validMarkers[id]?.getTailPosition()
setMarkerTailPosition: (id, position, options) ->
@validMarkers[id]?.setTailPosition(position)
getMarkerRange: (id) ->
@validMarkers[id]?.getRange()