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