mirror of
https://github.com/atom/atom.git
synced 2026-02-14 00:25:08 -05:00
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:
@@ -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
|
||||
|
||||
@@ -295,6 +295,9 @@ class Buffer
|
||||
getMarkerRange: (id) ->
|
||||
@validMarkers[id]?.getRange()
|
||||
|
||||
isMarkerReversed: (id) ->
|
||||
@validMarkers[id]?.isReversed()
|
||||
|
||||
getAnchors: -> new Array(@anchors...)
|
||||
|
||||
addAnchor: (options) ->
|
||||
|
||||
Reference in New Issue
Block a user