mirror of
https://github.com/atom/atom.git
synced 2026-01-25 14:59:03 -05:00
WIP: Start converting cursor and selection to be based on markers
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
Point = require 'point'
|
||||
Range = require 'range'
|
||||
Anchor = require 'anchor'
|
||||
EventEmitter = require 'event-emitter'
|
||||
_ = require 'underscore'
|
||||
|
||||
@@ -12,19 +11,15 @@ class Cursor
|
||||
visible: true
|
||||
needsAutoscroll: null
|
||||
|
||||
constructor: ({@editSession, screenPosition, bufferPosition}) ->
|
||||
@anchor = @editSession.addAnchor(strong: true)
|
||||
@anchor.on 'moved', (e) =>
|
||||
@needsAutoscroll ?= @isLastCursor()
|
||||
@trigger 'moved', e
|
||||
@editSession.trigger 'cursor-moved', e
|
||||
|
||||
@setScreenPosition(screenPosition) if screenPosition
|
||||
@setBufferPosition(bufferPosition) if bufferPosition
|
||||
constructor: ({@editSession, @marker}) ->
|
||||
# @editSession.observeMarkerHeadScreenPosition @marker, (screenPosition) ->
|
||||
# @needsAutoscroll ?= @isLastCursor()
|
||||
# @trigger 'moved', e
|
||||
# @editSession.trigger 'cursor-moved', e
|
||||
@needsAutoscroll = true
|
||||
|
||||
destroy: ->
|
||||
@anchor.destroy()
|
||||
@editSession.destroyMarker(@marker)
|
||||
@editSession.removeCursor(this)
|
||||
@trigger 'destroyed'
|
||||
|
||||
@@ -32,22 +27,19 @@ class Cursor
|
||||
@goalColumn = null
|
||||
@clearSelection()
|
||||
@needsAutoscroll = (options.autoscroll ? true) and @isLastCursor()
|
||||
@anchor.setScreenPosition(screenPosition, options)
|
||||
@editSession.setMarkerHeadScreenPosition(@marker, screenPosition, options)
|
||||
|
||||
getScreenPosition: ->
|
||||
@anchor.getScreenPosition()
|
||||
|
||||
getScreenRow: ->
|
||||
@anchor.getScreenRow()
|
||||
@editSession.getMarkerHeadScreenPosition(@marker)
|
||||
|
||||
setBufferPosition: (bufferPosition, options={}) ->
|
||||
@goalColumn = null
|
||||
@clearSelection()
|
||||
@needsAutoscroll = options.autoscroll ? @isLastCursor()
|
||||
@anchor.setBufferPosition(bufferPosition, options)
|
||||
@editSession.setMarkerHeadBufferPosition(@marker, screenPosition, options)
|
||||
|
||||
getBufferPosition: ->
|
||||
@anchor.getBufferPosition()
|
||||
@editSession.getMarkerHeadBufferPosition(@marker)
|
||||
|
||||
setVisible: (visible) ->
|
||||
if @visible != visible
|
||||
@@ -91,9 +83,6 @@ class Cursor
|
||||
getCurrentBufferLine: ->
|
||||
@editSession.lineForBufferRow(@getBufferRow())
|
||||
|
||||
refreshScreenPosition: ->
|
||||
@anchor.refreshScreenPosition()
|
||||
|
||||
moveUp: (rowCount = 1) ->
|
||||
{ row, column } = @getScreenPosition()
|
||||
column = @goalColumn if @goalColumn?
|
||||
|
||||
@@ -434,6 +434,18 @@ class EditSession
|
||||
getAnchorRanges: ->
|
||||
new Array(@anchorRanges...)
|
||||
|
||||
markScreenPosition: (args...) ->
|
||||
@displayBuffer.markScreenPosition(args...)
|
||||
|
||||
markBufferPosition: (args...) ->
|
||||
@displayBuffer.markBufferPosition(args...)
|
||||
|
||||
getMarkerBufferRange: (marker) ->
|
||||
@displayBuffer.getMarkerBufferRange(marker)
|
||||
|
||||
getMarkerScreenRange: (marker) ->
|
||||
@displayBuffer.getMarkerScreenRange(marker)
|
||||
|
||||
addAnchor: (options={}) ->
|
||||
anchor = @buffer.addAnchor(_.extend({editSession: this}, options))
|
||||
@anchors.push(anchor)
|
||||
@@ -470,31 +482,35 @@ class EditSession
|
||||
_.last(@cursors)
|
||||
|
||||
addCursorAtScreenPosition: (screenPosition) ->
|
||||
@addCursor(new Cursor(editSession: this, screenPosition: screenPosition))
|
||||
marker = @markScreenPosition(screenPosition, stayValid: true)
|
||||
@addSelection(marker).cursor
|
||||
|
||||
addCursorAtBufferPosition: (bufferPosition) ->
|
||||
@addCursor(new Cursor(editSession: this, bufferPosition: bufferPosition))
|
||||
marker = @markBufferPosition(screenPosition, stayValid: true)
|
||||
@addSelection(marker).cursor
|
||||
|
||||
addCursor: (cursor=new Cursor(editSession: this, screenPosition: [0,0])) ->
|
||||
addCursor: (marker) ->
|
||||
cursor = new Cursor(editSession: this, marker: marker)
|
||||
@cursors.push(cursor)
|
||||
@trigger 'cursor-added', cursor
|
||||
@addSelectionForCursor(cursor)
|
||||
cursor
|
||||
|
||||
removeCursor: (cursor) ->
|
||||
_.remove(@cursors, cursor)
|
||||
|
||||
addSelectionForCursor: (cursor) ->
|
||||
selection = new Selection(editSession: this, cursor: cursor)
|
||||
addSelection: (marker, options={}) ->
|
||||
unless options.preserveFolds
|
||||
@destroyFoldsIntersectingBufferRange(@getMarkerBufferRange(marker))
|
||||
cursor = @addCursor(marker)
|
||||
selection = new Selection({editSession: this, marker, cursor})
|
||||
@selections.push(selection)
|
||||
@mergeIntersectingSelections()
|
||||
@trigger 'selection-added', selection
|
||||
selection
|
||||
|
||||
addSelectionForBufferRange: (bufferRange, options={}) ->
|
||||
bufferRange = Range.fromObject(bufferRange)
|
||||
@destroyFoldsIntersectingBufferRange(bufferRange) unless options.preserveFolds
|
||||
@addCursor().selection.setBufferRange(bufferRange, options)
|
||||
@mergeIntersectingSelections()
|
||||
marker = @markBufferRange(bufferRange, _.defaults({stayValid: true}, options))
|
||||
@addSelection(marker)
|
||||
|
||||
setSelectedBufferRange: (bufferRange, options) ->
|
||||
@setSelectedBufferRanges([bufferRange], options)
|
||||
|
||||
@@ -1086,7 +1086,7 @@ class Editor extends View
|
||||
if fold = screenLine.fold
|
||||
lineAttributes = { class: 'fold line', 'fold-id': fold.id }
|
||||
else
|
||||
lineAttributes = { class: 'line' }
|
||||
lineAttributes = { class: 'line' }
|
||||
|
||||
attributePairs = []
|
||||
attributePairs.push "#{attributeName}=\"#{value}\"" for attributeName, value of lineAttributes
|
||||
@@ -1117,7 +1117,7 @@ class Editor extends View
|
||||
if invisibles.eol
|
||||
line.push("<span class='invisible'>#{invisibles.eol}</span>")
|
||||
|
||||
line.push("<span class='fold-marker'/>") if fold
|
||||
# line.push("<span class='fold-marker'/>") if fold
|
||||
|
||||
line.push('</pre>')
|
||||
line.join('')
|
||||
|
||||
Reference in New Issue
Block a user