Remove methods from CompositeCursor + more 💄

This commit is contained in:
Nathan Sobo
2012-06-08 19:08:44 -06:00
parent f8369d2ea1
commit 80cd63227a
5 changed files with 41 additions and 103 deletions

View File

@@ -6,14 +6,11 @@ class CompositeCursor
constructor: (@editor) ->
@cursors = []
handleBufferChange: (e) ->
@moveCursors (cursor) -> cursor.handleBufferChange(e)
getCursor: (index) ->
getCursorView: (index) ->
index ?= @cursors.length - 1
@cursors[index]
getCursors: ->
getCursorViews: ->
@cursors
addCursorView: (cursor) ->
@@ -26,69 +23,11 @@ class CompositeCursor
for view in @getCursors()
return view if view.cursor == cursor
removeAllCursors: ->
cursor.remove() for cursor in @getCursors()
removeAllCursorViews: ->
cursor.remove() for cursor in @getCursorViews()
removeCursor: (cursor) ->
_.remove(@cursors, cursor)
updateAppearance: ->
cursor.updateAppearance() for cursor in @cursors
moveCursors: (fn) ->
fn(cursor) for cursor in @cursors
@mergeCursors()
setScreenPosition: (screenPosition) ->
@moveCursors (cursor) -> cursor.setScreenPosition(screenPosition)
setBufferPosition: (bufferPosition) ->
@moveCursors (cursor) -> cursor.setBufferPosition(bufferPosition)
updateBufferPosition: ->
@moveCursors (cursor) -> cursor.setBufferPosition(cursor.getBufferPosition())
moveLeft: ->
@moveCursors (cursor) -> cursor.moveLeft()
moveRight: ->
@moveCursors (cursor) -> cursor.moveRight()
moveUp: ->
@moveCursors (cursor) -> cursor.moveUp()
moveDown: ->
@moveCursors (cursor) -> cursor.moveDown()
moveToNextWord: ->
@moveCursors (cursor) -> cursor.moveToNextWord()
moveToBeginningOfWord: ->
@moveCursors (cursor) -> cursor.moveToBeginningOfWord()
moveToEndOfWord: ->
@moveCursors (cursor) -> cursor.moveToEndOfWord()
moveToTop: ->
@moveCursors (cursor) -> cursor.moveToTop()
moveToBottom: ->
@moveCursors (cursor) -> cursor.moveToBottom()
moveToBeginningOfLine: ->
@moveCursors (cursor) -> cursor.moveToBeginningOfLine()
moveToEndOfLine: ->
@moveCursors (cursor) -> cursor.moveToEndOfLine()
moveToFirstCharacterOfLine: ->
@moveCursors (cursor) -> cursor.moveToFirstCharacterOfLine()
mergeCursors: ->
positions = []
for cursor in new Array(@cursors...)
position = cursor.getBufferPosition().toString()
if position in positions
cursor.remove()
else
positions.push(position)

View File

@@ -37,7 +37,7 @@ class CursorView extends View
pixelPosition = @editor.pixelPositionForScreenPosition(screenPosition)
@css(pixelPosition)
if this == _.last(@editor.getCursors())
if @cursor == @editor.getLastCursor()
@editor.scrollTo(pixelPosition)
if @editor.isFoldedAtScreenRow(screenPosition.row)

View File

@@ -357,7 +357,7 @@ class Editor extends View
if @activeEditSession
@saveActiveEditSession()
@compositeCursor.removeAllCursors()
@removeAllCursorViews()
@activeEditSession.off()
@activeEditSession = @editSessions[index]
@@ -650,7 +650,11 @@ class Editor extends View
@compositeCursor.updateAppearance()
@updateRenderedLines()
getCursors: -> @compositeCursor.getCursors()
getCursorView: (index) -> @compositeCursor.getCursorView(index)
getCursorViews: -> @compositeCursor.getCursorViews()
removeAllCursorViews: -> @compositeCursor.removeAllCursorViews()
getCursors: -> @activeEditSession.getCursors()
getLastCursor: -> @activeEditSession.getLastCursor()
moveCursorUp: -> @activeEditSession.moveCursorUp()
moveCursorDown: -> @activeEditSession.moveCursorDown()
moveCursorLeft: -> @activeEditSession.moveCursorLeft()
@@ -826,8 +830,8 @@ class Editor extends View
@scrollView.scrollLeft(desiredLeft)
syncCursorAnimations: ->
for cursor in @getCursors()
do (cursor) -> cursor.resetCursorAnimation()
for cursorView in @getCursorViews()
do (cursorView) -> cursorView.resetCursorAnimation()
foldAll: ->
@renderer.foldAll()