Move moveLeft/Right/ToTop/ToBottom methods into cursor model

This commit is contained in:
Nathan Sobo
2012-06-07 10:57:21 -06:00
parent ddf29e89ec
commit fccc88acaf
5 changed files with 38 additions and 29 deletions

View File

@@ -29,8 +29,6 @@ class CursorView extends View
handleBufferChange: (e) ->
@cursor.handleBufferChange(e)
# @anchor.handleBufferChange(e)
# @refreshScreenPosition()
@trigger 'cursor-move', bufferChange: true
remove: ->
@@ -44,10 +42,6 @@ class CursorView extends View
setBufferPosition: (bufferPosition, options={}) ->
@cursor.setBufferPosition(bufferPosition, options)
# @anchor.setBufferPosition(bufferPosition, options)
# @refreshScreenPosition()
# @trigger 'cursor-move', bufferChange: false
# @clearSelection()
getScreenPosition: ->
@anchor.getScreenPosition()
@@ -152,21 +146,6 @@ class CursorView extends View
newPosition = [position.row, 0] if newPosition.isEqual(position)
@setBufferPosition(newPosition)
moveRight: ->
{ row, column } = @getScreenPosition()
@setScreenPosition([row, column + 1], skipAtomicTokens: true, wrapBeyondNewlines: true, wrapAtSoftNewlines: true)
moveLeft: ->
{ row, column } = @getScreenPosition()
[row, column] = if column > 0 then [row, column - 1] else [row - 1, Infinity]
@setScreenPosition({row, column})
moveToTop: ->
@setBufferPosition [0,0]
moveToBottom: ->
@setBufferPosition @editor.getEofPosition()
updateAppearance: ->
screenPosition = @getScreenPosition()
pixelPosition = @editor.pixelPositionForScreenPosition(screenPosition)

View File

@@ -46,6 +46,21 @@ class Cursor
@setScreenPosition({row: row + 1, column: column})
@goalColumn = column
moveLeft: ->
{ row, column } = @getScreenPosition()
[row, column] = if column > 0 then [row, column - 1] else [row - 1, Infinity]
@setScreenPosition({row, column})
moveRight: ->
{ row, column } = @getScreenPosition()
@setScreenPosition([row, column + 1], skipAtomicTokens: true, wrapBeyondNewlines: true, wrapAtSoftNewlines: true)
moveToTop: ->
@setBufferPosition([0,0])
moveToBottom: ->
@setBufferPosition(@editSession.getEofBufferPosition())
destroy: ->
@editSession.removeCursor(this)
@trigger 'destroy'

View File

@@ -51,6 +51,9 @@ class EditSession
clipScreenPosition: (screenPosition, options) ->
@renderer.clipScreenPosition(screenPosition, options)
getEofBufferPosition: ->
@buffer.getEofPosition()
getCursors: -> @cursors
addCursorAtScreenPosition: (screenPosition) ->
@@ -88,6 +91,18 @@ class EditSession
moveCursorDown: ->
@moveCursors (cursor) -> cursor.moveDown()
moveCursorLeft: ->
@moveCursors (cursor) -> cursor.moveLeft()
moveCursorRight: ->
@moveCursors (cursor) -> cursor.moveRight()
moveCursorToTop: ->
@moveCursors (cursor) -> cursor.moveToTop()
moveCursorToBottom: ->
@moveCursors (cursor) -> cursor.moveToBottom()
moveCursors: (fn) ->
fn(cursor) for cursor in @getCursors()
@mergeCursors()

View File

@@ -642,13 +642,13 @@ class Editor extends View
getCursors: -> @compositeCursor.getCursors()
moveCursorUp: -> @activeEditSession.moveCursorUp()
moveCursorDown: -> @activeEditSession.moveCursorDown()
moveCursorRight: -> @compositeCursor.moveRight()
moveCursorLeft: -> @compositeCursor.moveLeft()
moveCursorLeft: -> @activeEditSession.moveCursorLeft()
moveCursorRight: -> @activeEditSession.moveCursorRight()
moveCursorToNextWord: -> @compositeCursor.moveToNextWord()
moveCursorToBeginningOfWord: -> @compositeCursor.moveToBeginningOfWord()
moveCursorToEndOfWord: -> @compositeCursor.moveToEndOfWord()
moveCursorToTop: -> @compositeCursor.moveToTop()
moveCursorToBottom: -> @compositeCursor.moveToBottom()
moveCursorToTop: -> @activeEditSession.moveCursorToTop()
moveCursorToBottom: -> @activeEditSession.moveCursorToBottom()
moveCursorToBeginningOfLine: -> @compositeCursor.moveToBeginningOfLine()
moveCursorToFirstCharacterOfLine: -> @compositeCursor.moveToFirstCharacterOfLine()
moveCursorToEndOfLine: -> @compositeCursor.moveToEndOfLine()

View File

@@ -202,10 +202,10 @@ class Selection extends View
@modifySelection => @cursor.setScreenPosition(position)
selectRight: ->
@modifySelection => @cursor.moveRight()
@modifySelection => @cursor.cursor.moveRight()
selectLeft: ->
@modifySelection => @cursor.moveLeft()
@modifySelection => @cursor.cursor.moveLeft()
selectUp: ->
@modifySelection => @cursor.cursor.moveUp()
@@ -214,10 +214,10 @@ class Selection extends View
@modifySelection => @cursor.cursor.moveDown()
selectToTop: ->
@modifySelection => @cursor.moveToTop()
@modifySelection => @cursor.cursor.moveToTop()
selectToBottom: ->
@modifySelection => @cursor.moveToBottom()
@modifySelection => @cursor.cursor.moveToBottom()
selectAll: ->
@setBufferRange(@editor.buffer.getRange())