Rely on clipScreenPosition in vertical movement methods

Before, we were manually clipping the position of the cursor in
vertical movement methods. Now we can just increment / decrement the
row and the position will be clipped when it is assigned.

Also, changed the definition of clip screen position to always 0 out
the column when the row is negative.
This commit is contained in:
Nathan Sobo
2012-02-27 13:16:21 -07:00
parent f24a045e11
commit f2f401e5a1
4 changed files with 9 additions and 6 deletions

View File

@@ -50,11 +50,7 @@ class Cursor extends View
moveUp: ->
{ row, column } = @getScreenPosition()
column = @goalColumn if @goalColumn?
if row > 0
@setScreenPosition({row: row - 1, column: column})
else
@moveToLineStart()
@setScreenPosition({row: row - 1, column: column})
@goalColumn = column
moveDown: ->

View File

@@ -144,7 +144,12 @@ class LineMap
clipScreenPosition: (screenPosition, eagerWrap) ->
screenPosition = Point.fromObject(screenPosition)
screenPosition = new Point(Math.max(0, screenPosition.row), Math.max(0, screenPosition.column))
screenPosition.column = Math.max(0, screenPosition.column)
if screenPosition.row < 0
screenPosition.row = 0
screenPosition.column = 0
maxRow = @lastScreenRow()
if screenPosition.row > maxRow
screenPosition.row = maxRow