mirror of
https://github.com/atom/atom.git
synced 2026-02-14 08:35:11 -05:00
Previously an inserted automcomplete match would not update the case of the prefix or suffix of the match and instead only insert the text from the matched word between the prefix and suffix. Now the entire matched word is inserted as-is replacing the existing prefix and suffix.
85 lines
2.1 KiB
CoffeeScript
85 lines
2.1 KiB
CoffeeScript
Point = require 'point'
|
|
_ = require 'underscore'
|
|
|
|
module.exports =
|
|
class Range
|
|
@fromObject: (object) ->
|
|
if _.isArray(object)
|
|
new Range(object...)
|
|
else if object instanceof Range
|
|
object
|
|
else
|
|
new Range(object.start, object.end)
|
|
|
|
@fromPointWithDelta: (point, rowDelta, columnDelta) ->
|
|
pointA = Point.fromObject(point)
|
|
pointB = new Point(point.row + rowDelta, point.column + columnDelta)
|
|
new Range(pointA, pointB)
|
|
|
|
constructor: (pointA = new Point(0, 0), pointB = new Point(0, 0)) ->
|
|
pointA = Point.fromObject(pointA)
|
|
pointB = Point.fromObject(pointB)
|
|
|
|
if pointA.compare(pointB) <= 0
|
|
@start = pointA
|
|
@end = pointB
|
|
else
|
|
@start = pointB
|
|
@end = pointA
|
|
|
|
copy: ->
|
|
new Range(@start.copy(), @end.copy())
|
|
|
|
isEqual: (other) ->
|
|
if other instanceof Array and other.length == 2
|
|
other = new Range(other...)
|
|
|
|
other.start.isEqual(@start) and other.end.isEqual(@end)
|
|
|
|
isSingleLine: ->
|
|
@start.row == @end.row
|
|
|
|
coversSameRows: (other) ->
|
|
@start.row == other.start.row && @end.row == other.end.row
|
|
|
|
inspect: ->
|
|
"[#{@start.inspect()} - #{@end.inspect()}]"
|
|
|
|
add: (point) ->
|
|
new Range(@start.add(point), @end.add(point))
|
|
|
|
intersectsWith: (otherRange) ->
|
|
if @start.isLessThanOrEqual(otherRange.start)
|
|
@end.isGreaterThanOrEqual(otherRange.start)
|
|
else
|
|
otherRange.intersectsWith(this)
|
|
|
|
containsPoint: (point, { exclusive } = {}) ->
|
|
point = Point.fromObject(point)
|
|
if exclusive
|
|
point.isGreaterThan(@start) and point.isLessThan(@end)
|
|
else
|
|
point.isGreaterThanOrEqual(@start) and point.isLessThanOrEqual(@end)
|
|
|
|
containsRow: (row) ->
|
|
@start.row <= row <= @end.row
|
|
|
|
union: (otherRange) ->
|
|
start = if @start.isLessThan(otherRange.start) then @start else otherRange.start
|
|
end = if @end.isGreaterThan(otherRange.end) then @end else otherRange.end
|
|
new Range(start, end)
|
|
|
|
isEmpty: ->
|
|
@start.isEqual(@end)
|
|
|
|
toDelta: ->
|
|
rows = @end.row - @start.row
|
|
if rows == 0
|
|
columns = @end.column - @start.column
|
|
else
|
|
columns = @end.column
|
|
new Point(rows, columns)
|
|
|
|
getRowCount: ->
|
|
@end.row - @start.row + 1
|