mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
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:
@@ -320,6 +320,7 @@ describe "LineFolder", ->
|
||||
it "returns the nearest valid position based on the current screen lines", ->
|
||||
expect(folder.clipScreenPosition([-1, -1])).toEqual [0, 0]
|
||||
expect(folder.clipScreenPosition([0, -1])).toEqual [0, 0]
|
||||
expect(folder.clipScreenPosition([-1, 5])).toEqual [0, 0]
|
||||
expect(folder.clipScreenPosition([1, 10000])).toEqual [1, 30]
|
||||
expect(folder.clipScreenPosition([2, 15])).toEqual [2, 15]
|
||||
expect(folder.clipScreenPosition([4, 32])).toEqual [4, 32]
|
||||
|
||||
@@ -244,6 +244,7 @@ describe "LineWrapper", ->
|
||||
|
||||
it "disallows negative positions", ->
|
||||
expect(wrapper.clipScreenPosition([-1, -1])).toEqual [0, 0]
|
||||
expect(wrapper.clipScreenPosition([-1, 10])).toEqual [0, 0]
|
||||
expect(wrapper.clipScreenPosition([0, -1])).toEqual [0, 0]
|
||||
|
||||
it "disallows positions beyond the last row", ->
|
||||
|
||||
@@ -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: ->
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user