CompositeCursor.addCursor takes an optional screenPosition argument

This commit is contained in:
Corey Johnson
2012-04-04 14:08:21 -07:00
parent 48b4008cab
commit 2489e19bb7
5 changed files with 24 additions and 14 deletions

View File

@@ -6,10 +6,14 @@ class Anchor
bufferPosition: null
screenPosition: null
constructor: (editor) ->
constructor: (editor, screenPosition) ->
@editor = editor
@bufferPosition = new Point(0, 0)
@screenPosition = new Point(0, 0)
if screenPosition
@setScreenPosition(screenPosition)
else
@bufferPosition = new Point(0,0)
@screenPosition = new Point(0,0)
handleBufferChange: (e) ->
{ oldRange, newRange } = e

View File

@@ -17,19 +17,18 @@ class CompositeCursor
getCursors: ->
@cursors
addCursor: ->
cursor = new Cursor(@editor)
addCursor: (screenPosition=null) ->
cursor = new Cursor({@editor, screenPosition})
@cursors.push(cursor)
@editor.lines.append(cursor)
cursor
addCursorAtScreenPosition: (screenPosition) ->
cursor = @addCursor()
cursor.setScreenPosition(screenPosition)
cursor = @addCursor(screenPosition)
addCursorAtBufferPosition: (bufferPosition) ->
cursor = @addCursor()
cursor.setBufferPosition(bufferPosition)
screenPosition = @editor.screenPositionForBufferPosition(bufferPosition)
cursor = @addCursor(screenPosition)
removeCursor: (cursor) ->
_.remove(@cursors, cursor)

View File

@@ -12,8 +12,9 @@ class Cursor extends View
editor: null
wordRegex: /(\w+)|([^\w\s]+)/g
initialize: (@editor) ->
@anchor = new Anchor(@editor)
initialize: ({editor, screenPosition}) ->
@editor = editor
@anchor = new Anchor(@editor, screenPosition)
@selection = @editor.compositeSelection.addSelectionForCursor(this)
@one 'attach', => @updateAppearance()

View File

@@ -482,9 +482,9 @@ class Editor extends View
@buffer.getMode()
scrollTo: (pixelPosition) ->
_.defer =>
@scrollVertically(pixelPosition)
@scrollHorizontally(pixelPosition)
_.defer => # Optimization
@scrollVertically(pixelPosition)
@scrollHorizontally(pixelPosition)
scrollVertically: (pixelPosition) ->
linesInView = @scroller.height() / @lineHeight