mirror of
https://github.com/atom/atom.git
synced 2026-02-14 00:25:08 -05:00
EditSession specs passing after converting Selection to use markers
Still a bit of a mess though...
This commit is contained in:
@@ -92,6 +92,7 @@ class BufferChangeOperation
|
||||
|
||||
updateMarkers: (bufferChange) ->
|
||||
marker.handleBufferChange(bufferChange) for marker in @buffer.getMarkers()
|
||||
@buffer.trigger 'markers-updated'
|
||||
|
||||
restoreMarkers: (markersToRestore) ->
|
||||
for [id, previousRange] in markersToRestore
|
||||
|
||||
@@ -51,6 +51,12 @@ class BufferMarker
|
||||
getEndPosition: ->
|
||||
@getRange().end
|
||||
|
||||
placeTail: ->
|
||||
@setTailPosition(@headPosition) unless @tailPosition
|
||||
|
||||
clearTail: ->
|
||||
@tailPosition = null
|
||||
|
||||
observeHeadPosition: (callback) ->
|
||||
@headPositionObservers.push(callback)
|
||||
cancel: =>
|
||||
|
||||
@@ -308,6 +308,15 @@ class Buffer
|
||||
getMarkerRange: (id) ->
|
||||
@validMarkers[id]?.getRange()
|
||||
|
||||
setMarkerRange: (id, range, options) ->
|
||||
@validMarkers[id]?.setRange(range, options)
|
||||
|
||||
placeMarkerTail: (id) ->
|
||||
@validMarkers[id]?.placeTail()
|
||||
|
||||
clearMarkerTail: (id) ->
|
||||
@validMarkers[id]?.clearTail()
|
||||
|
||||
isMarkerReversed: (id) ->
|
||||
@validMarkers[id]?.isReversed()
|
||||
|
||||
|
||||
@@ -303,14 +303,14 @@ class DisplayBuffer
|
||||
markScreenRange: (screenRange) ->
|
||||
@markBufferRange(@bufferRangeForScreenRange(screenRange))
|
||||
|
||||
markBufferRange: (bufferRange) ->
|
||||
@buffer.markRange(bufferRange)
|
||||
markBufferRange: (args...) ->
|
||||
@buffer.markRange(args...)
|
||||
|
||||
markScreenPosition: (screenPosition) ->
|
||||
@markBufferPosition(@bufferPositionForScreenPosition(screenPosition))
|
||||
markScreenPosition: (screenPosition, options) ->
|
||||
@markBufferPosition(@bufferPositionForScreenPosition(screenPosition), options)
|
||||
|
||||
markBufferPosition: (bufferPosition) ->
|
||||
@buffer.markPosition(bufferPosition)
|
||||
markBufferPosition: (bufferPosition, options) ->
|
||||
@buffer.markPosition(bufferPosition, options)
|
||||
|
||||
destroyMarker: (id) ->
|
||||
@buffer.destroyMarker(id)
|
||||
@@ -320,9 +320,15 @@ class DisplayBuffer
|
||||
getMarkerScreenRange: (id) ->
|
||||
@screenRangeForBufferRange(@getMarkerBufferRange(id))
|
||||
|
||||
setMarkerScreenRange: (id, screenRange, options) ->
|
||||
@setMarkerBufferRange(id, @bufferRangeForScreenRange(screenRange), options)
|
||||
|
||||
getMarkerBufferRange: (id) ->
|
||||
@buffer.getMarkerRange(id)
|
||||
|
||||
setMarkerBufferRange: (id, bufferRange, options) ->
|
||||
@buffer.setMarkerRange(id, bufferRange, options)
|
||||
|
||||
getMarkerScreenPosition: (id) ->
|
||||
@getMarkerHeadScreenPosition(id)
|
||||
|
||||
@@ -355,6 +361,12 @@ class DisplayBuffer
|
||||
setMarkerTailBufferPosition: (id, bufferPosition) ->
|
||||
@buffer.setMarkerTailPosition(id, bufferPosition)
|
||||
|
||||
placeMarkerTail: (id) ->
|
||||
@buffer.placeMarkerTail(id)
|
||||
|
||||
clearMarkerTail: (id) ->
|
||||
@buffer.clearMarkerTail(id)
|
||||
|
||||
isMarkerReversed: (id) ->
|
||||
@buffer.isMarkerReversed(id)
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ class EditSession
|
||||
@buffer.retain()
|
||||
@subscribe @buffer, "path-changed", => @trigger "path-changed"
|
||||
@subscribe @buffer, "contents-conflicted", => @trigger "contents-conflicted"
|
||||
@subscribe @buffer, "anchors-updated", => @mergeCursors()
|
||||
@subscribe @buffer, "markers-updated", => @mergeCursors()
|
||||
|
||||
@preserveCursorPositionOnBufferReload()
|
||||
|
||||
@@ -434,6 +434,12 @@ class EditSession
|
||||
getAnchorRanges: ->
|
||||
new Array(@anchorRanges...)
|
||||
|
||||
markScreenRange: (args...) ->
|
||||
@displayBuffer.markScreenRange(args...)
|
||||
|
||||
markBufferRange: (args...) ->
|
||||
@displayBuffer.markBufferRange(args...)
|
||||
|
||||
markScreenPosition: (args...) ->
|
||||
@displayBuffer.markScreenPosition(args...)
|
||||
|
||||
@@ -443,11 +449,17 @@ class EditSession
|
||||
destroyMarker: (args...) ->
|
||||
@displayBuffer.destroyMarker(args...)
|
||||
|
||||
getMarkerScreenRange: (args...) ->
|
||||
@displayBuffer.getMarkerScreenRange(args...)
|
||||
|
||||
setMarkerScreenRange: (args...) ->
|
||||
@displayBuffer.setMarkerScreenRange(args...)
|
||||
|
||||
getMarkerBufferRange: (args...) ->
|
||||
@displayBuffer.getMarkerBufferRange(args...)
|
||||
|
||||
getMarkerScreenRange: (args...) ->
|
||||
@displayBuffer.getMarkerScreenRange(args...)
|
||||
setMarkerBufferRange: (args...) ->
|
||||
@displayBuffer.setMarkerBufferRange(args...)
|
||||
|
||||
getMarkerScreenPosition: (args...) ->
|
||||
@displayBuffer.getMarkerScreenPosition(args...)
|
||||
@@ -482,6 +494,15 @@ class EditSession
|
||||
observeMarkerHeadScreenPosition: (args...) ->
|
||||
@displayBuffer.observeMarkerHeadScreenPosition(args...)
|
||||
|
||||
placeMarkerTail: (args...) ->
|
||||
@displayBuffer.placeMarkerTail(args...)
|
||||
|
||||
clearMarkerTail: (args...) ->
|
||||
@displayBuffer.clearMarkerTail(args...)
|
||||
|
||||
isMarkerReversed: (args...) ->
|
||||
@displayBuffer.isMarkerReversed(args...)
|
||||
|
||||
addAnchor: (options={}) ->
|
||||
anchor = @buffer.addAnchor(_.extend({editSession: this}, options))
|
||||
@anchors.push(anchor)
|
||||
@@ -545,7 +566,8 @@ class EditSession
|
||||
selection
|
||||
|
||||
addSelectionForBufferRange: (bufferRange, options={}) ->
|
||||
marker = @markBufferRange(bufferRange, _.defaults({stayValid: true}, options))
|
||||
options = _.defaults({stayValid: true}, options)
|
||||
marker = @markBufferRange(bufferRange, options)
|
||||
@addSelection(marker)
|
||||
|
||||
setSelectedBufferRange: (bufferRange, options) ->
|
||||
@@ -741,7 +763,7 @@ class EditSession
|
||||
|
||||
mergeCursors: ->
|
||||
positions = []
|
||||
for cursor in new Array(@getCursors()...)
|
||||
for cursor in @getCursors()
|
||||
position = cursor.getBufferPosition().toString()
|
||||
if position in positions
|
||||
cursor.destroy()
|
||||
|
||||
@@ -5,12 +5,11 @@ _ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
class Selection
|
||||
anchor: null
|
||||
wordwise: false
|
||||
initialScreenRange: null
|
||||
needsAutoscroll: null
|
||||
|
||||
constructor: ({@cursor, @editSession}) ->
|
||||
constructor: ({@cursor, @marker, @editSession}) ->
|
||||
@cursor.selection = this
|
||||
|
||||
@cursor.on 'moved.selection', ({bufferChange}) =>
|
||||
@@ -24,7 +23,6 @@ class Selection
|
||||
if @cursor
|
||||
@cursor.off('.selection')
|
||||
@cursor.destroy()
|
||||
@anchor?.destroy()
|
||||
@editSession.removeSelection(this)
|
||||
@trigger 'destroyed'
|
||||
|
||||
@@ -38,7 +36,7 @@ class Selection
|
||||
@getBufferRange().isEmpty()
|
||||
|
||||
isReversed: ->
|
||||
not @isEmpty() and @cursor.getBufferPosition().isLessThan(@anchor.getBufferPosition())
|
||||
@editSession.isMarkerReversed(@marker)
|
||||
|
||||
isSingleScreenLine: ->
|
||||
@getScreenRange().isSingleLine()
|
||||
@@ -47,33 +45,21 @@ class Selection
|
||||
@needsAutoscroll = null
|
||||
|
||||
getScreenRange: ->
|
||||
if @anchor
|
||||
new Range(@anchor.getScreenPosition(), @cursor.getScreenPosition())
|
||||
else
|
||||
new Range(@cursor.getScreenPosition(), @cursor.getScreenPosition())
|
||||
@editSession.getMarkerScreenRange(@marker)
|
||||
|
||||
setScreenRange: (screenRange, options) ->
|
||||
bufferRange = editSession.bufferRangeForScreenRange(screenRange)
|
||||
@setBufferRange(bufferRange, options)
|
||||
@setBufferRange(@editSession.bufferRangeForScreenRange(screenRange), options)
|
||||
|
||||
getBufferRange: ->
|
||||
if @anchor
|
||||
new Range(@anchor.getBufferPosition(), @cursor.getBufferPosition())
|
||||
else
|
||||
new Range(@cursor.getBufferPosition(), @cursor.getBufferPosition())
|
||||
@editSession.getMarkerBufferRange(@marker)
|
||||
|
||||
setBufferRange: (bufferRange, options={}) ->
|
||||
bufferRange = Range.fromObject(bufferRange)
|
||||
{ start, end } = bufferRange
|
||||
[start, end] = [end, start] if options.reverse ? @isReversed()
|
||||
|
||||
@needsAutoscroll = options.autoscroll
|
||||
|
||||
options.reverse ?= @isReversed()
|
||||
@editSession.destroyFoldsIntersectingBufferRange(bufferRange) unless options.preserveFolds
|
||||
@placeAnchor() unless @anchor
|
||||
@modifySelection =>
|
||||
@anchor.setBufferPosition(start, autoscroll: false)
|
||||
@cursor.setBufferPosition(end, autoscroll: false)
|
||||
@editSession.setMarkerBufferRange(@marker, bufferRange, options)
|
||||
|
||||
getBufferRowRange: ->
|
||||
range = @getBufferRange()
|
||||
@@ -91,9 +77,7 @@ class Selection
|
||||
@editSession.buffer.getTextInRange(@getBufferRange())
|
||||
|
||||
clear: ->
|
||||
return unless @anchor
|
||||
@anchor.destroy()
|
||||
@anchor = null
|
||||
@editSession.clearMarkerTail(@marker)
|
||||
@screenRangeChanged()
|
||||
|
||||
selectWord: ->
|
||||
@@ -122,11 +106,9 @@ class Selection
|
||||
@modifySelection =>
|
||||
if @initialScreenRange
|
||||
if position.isLessThan(@initialScreenRange.start)
|
||||
@anchor.setScreenPosition(@initialScreenRange.end)
|
||||
@cursor.setScreenPosition(position)
|
||||
@editSession.setMarkerScreenRange(@marker, [position, @initialScreenRange.end], reverse: true)
|
||||
else
|
||||
@anchor.setScreenPosition(@initialScreenRange.start)
|
||||
@cursor.setScreenPosition(position)
|
||||
@editSession.setMarkerScreenRange(@marker, [@initialScreenRange.start, position])
|
||||
else
|
||||
@cursor.setScreenPosition(position)
|
||||
|
||||
@@ -318,8 +300,7 @@ class Selection
|
||||
@editSession.autoIndentBufferRows(start, end)
|
||||
|
||||
toggleLineComments: ->
|
||||
@modifySelection =>
|
||||
@editSession.toggleLineCommentsForBufferRows(@getBufferRowRange()...)
|
||||
@editSession.toggleLineCommentsForBufferRows(@getBufferRowRange()...)
|
||||
|
||||
cutToEndOfLine: (maintainPasteboard) ->
|
||||
@selectToEndOfLine() if @isEmpty()
|
||||
@@ -353,18 +334,16 @@ class Selection
|
||||
|
||||
modifySelection: (fn) ->
|
||||
@retainSelection = true
|
||||
@placeAnchor() unless @anchor
|
||||
@anchor.pauseEvents()
|
||||
@cursor.pauseEvents()
|
||||
@editSession.placeMarkerTail(@marker)
|
||||
# @anchor.pauseEvents()
|
||||
# @cursor.pauseEvents()
|
||||
fn()
|
||||
@anchor.resumeEvents()
|
||||
@cursor.resumeEvents()
|
||||
# @anchor.resumeEvents()
|
||||
# @cursor.resumeEvents()
|
||||
@retainSelection = false
|
||||
|
||||
placeAnchor: ->
|
||||
@anchor = @editSession.addAnchor(strong: true)
|
||||
@anchor.setScreenPosition(@cursor.getScreenPosition())
|
||||
@anchor.on 'moved.selection', => @screenRangeChanged()
|
||||
# placeAnchor: ->
|
||||
# @anchor.on 'moved.selection', => @screenRangeChanged()
|
||||
|
||||
intersectsBufferRange: (bufferRange) ->
|
||||
@getBufferRange().intersectsWith(bufferRange)
|
||||
|
||||
Reference in New Issue
Block a user