mirror of
https://github.com/atom/atom.git
synced 2026-02-13 16:14:59 -05:00
Support translating points and ranges
This commit is contained in:
@@ -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) ->
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user