Support translating points and ranges

This commit is contained in:
Kevin Sawicki
2013-01-30 13:48:36 -08:00
parent 06f64b5572
commit 1acf0b870f
5 changed files with 20 additions and 6 deletions

View File

@@ -369,9 +369,7 @@ class EditSession
@foldBufferRow(foldedRow) for foldedRow in foldedRows
newStartPosition = [selection.start.row - 1, selection.start.column]
newEndPosition = [selection.end.row - 1, selection.end.column]
@setSelectedBufferRange([newStartPosition, newEndPosition], preserveFolds: true)
@setSelectedBufferRange(selection.translate([-1]), preserveFolds: true)
moveLineDown: ->
selection = @getSelectedBufferRange()
@@ -408,9 +406,7 @@ class EditSession
@foldBufferRow(foldedRow) for foldedRow in foldedRows
newStartPosition = [selection.start.row + 1, selection.start.column]
newEndPosition = [selection.end.row + 1, selection.end.column]
@setSelectedBufferRange([newStartPosition, newEndPosition], preserveFolds: true)
@setSelectedBufferRange(selection.translate([1]), preserveFolds: true)
mutateSelectedText: (fn) ->

View File

@@ -34,6 +34,10 @@ class Point
new Point(row, column)
translate: (other) ->
other = Point.fromObject(other)
new Point(@row + other.row, @column + other.column)
splitAt: (column) ->
if @row == 0
rightColumn = @column - column

View File

@@ -48,6 +48,9 @@ class Range
add: (point) ->
new Range(@start.add(point), @end.add(point))
translate: (startPoint, endPoint=startPoint) ->
new Range(@start.translate(startPoint), @end.translate(endPoint))
intersectsWith: (otherRange) ->
if @start.isLessThanOrEqual(otherRange.start)
@end.isGreaterThanOrEqual(otherRange.start)