Allow markers to be created in a reverse orientation

This means that the head of the marker precedes its tail in the buffer.
This will be important if we want to build selections on top of markers.
This commit is contained in:
Nathan Sobo
2013-01-30 21:44:57 -07:00
parent d8ffdcd6bd
commit 5dd142b966
3 changed files with 21 additions and 4 deletions

View File

@@ -8,13 +8,20 @@ class BufferMarker
tailPosition: null
stayValid: false
constructor: ({@id, @buffer, range, @stayValid, noTail}) ->
@setRange(range, {noTail})
constructor: ({@id, @buffer, range, @stayValid, noTail, reverse}) ->
@setRange(range, {noTail, reverse})
setRange: (range, options={}) ->
range = @buffer.clipRange(range)
@tailPosition = range.start unless options.noTail
@headPosition = range.end
if options.reverse
@tailPosition = range.end unless options.noTail
@headPosition = range.start
else
@tailPosition = range.start unless options.noTail
@headPosition = range.end
isReversed: ->
@tailPosition? and @headPosition.isLessThan(@tailPosition)
getRange: ->
if @tailPosition

View File

@@ -295,6 +295,9 @@ class Buffer
getMarkerRange: (id) ->
@validMarkers[id]?.getRange()
isMarkerReversed: (id) ->
@validMarkers[id]?.isReversed()
getAnchors: -> new Array(@anchors...)
addAnchor: (options) ->