Allow markers to be created with just a position

When a marker is created with just a position, it only gets a head
position and has no tail position.
This commit is contained in:
Nathan Sobo
2013-01-30 21:37:57 -07:00
parent 0e67f35748
commit d8ffdcd6bd
3 changed files with 137 additions and 107 deletions

View File

@@ -8,16 +8,23 @@ class BufferMarker
tailPosition: null
stayValid: false
constructor: ({@id, @buffer, range, @stayValid}) ->
@setRange(range)
constructor: ({@id, @buffer, range, @stayValid, noTail}) ->
@setRange(range, {noTail})
setRange: (range) ->
setRange: (range, options={}) ->
range = @buffer.clipRange(range)
@tailPosition = range.start
@tailPosition = range.start unless options.noTail
@headPosition = range.end
getRange: ->
new Range(@tailPosition, @headPosition)
if @tailPosition
new Range(@tailPosition, @headPosition)
else
new Range(@headPosition, @headPosition)
getHeadPosition: -> @headPosition
getTailPosition: -> @tailPosition
getStartPosition: ->
@getRange().start

View File

@@ -271,17 +271,26 @@ class Buffer
getMarkers: ->
_.values(@validMarkers)
markRange: (range, options) ->
marker = new BufferMarker(_.extend({
markRange: (range, options={}) ->
marker = new BufferMarker(_.defaults({
id: @nextMarkerId++
buffer: this
range: range
range
}, options))
@validMarkers[marker.id] = marker
marker.id
markPosition: (position, options) ->
@markRange([position, position], _.defaults({noTail: true}, options))
getMarkerPosition: (id) ->
@validMarkers[id]?.getPosition()
@getMarkerHeadPosition(id)
getMarkerHeadPosition: (id) ->
@validMarkers[id]?.getHeadPosition()
getMarkerTailPosition: (id) ->
@validMarkers[id]?.getTailPosition()
getMarkerRange: (id) ->
@validMarkers[id]?.getRange()