Compare against EOF position when clipping

Previously the column could potentially be set to
zero since a Math.min comparison was used for the
length of an already adjusted row.
This commit is contained in:
Kevin Sawicki
2013-02-05 12:02:02 -08:00
parent 7ecafb1594
commit ad3c18077c
2 changed files with 23 additions and 7 deletions

View File

@@ -212,13 +212,15 @@ class Buffer
range
clipPosition: (position) ->
{ row, column } = Point.fromObject(position)
row = 0 if row < 0
column = 0 if column < 0
row = Math.min(@getLastRow(), row)
column = Math.min(@lineLengthForRow(row), column)
new Point(row, column)
position = Point.fromObject(position)
eofPosition = @getEofPosition()
if position.isGreaterThan(eofPosition)
eofPosition
else
row = Math.max(position.row, 0)
column = Math.max(position.column, 0)
column = Math.min(@lineLengthForRow(row), column)
new Point(row, column)
clipRange: (range) ->
range = Range.fromObject(range)