Remove Point and Range classes now provided by telepath

This commit is contained in:
Kevin Sawicki
2013-07-02 14:40:43 -07:00
parent e5ef23dc5a
commit f766bbbb38
40 changed files with 37 additions and 447 deletions

View File

@@ -2,7 +2,7 @@ nakedLoad 'jasmine-jquery'
$ = require 'jquery'
_ = require 'underscore'
Keymap = require 'keymap'
Point = require 'point'
{Point} = require 'telepath'
Config = require 'config'
Project = require 'project'

View File

@@ -2,7 +2,7 @@ RootView = require 'root-view'
EditSession = require 'edit-session'
Buffer = require 'text-buffer'
Editor = require 'editor'
Range = require 'range'
{Range} = require 'telepath'
Project = require 'project'
$ = require 'jquery'
{$$} = require 'space-pen'

View File

@@ -1,4 +1,4 @@
Point = require 'point'
{Point} = require 'telepath'
describe "Point", ->
describe ".isEqual(value)", ->

View File

@@ -1,5 +1,4 @@
Range = require 'range'
Point = require 'point'
{Point, Range} = require 'telepath'
describe "Range", ->
describe "constructor", ->

View File

@@ -1,6 +1,6 @@
Buffer = require 'text-buffer'
EditSession = require 'edit-session'
Range = require 'range'
{Range} = require 'telepath'
describe "Selection", ->
[buffer, editSession, selection] = []

View File

@@ -1,6 +1,6 @@
TokenizedBuffer = require 'tokenized-buffer'
Buffer = require 'text-buffer'
Range = require 'range'
{Range} = require 'telepath'
_ = require 'underscore'
describe "TokenizedBuffer", ->

View File

@@ -1,6 +1,6 @@
UndoManager = require 'undo-manager'
Buffer = require 'text-buffer'
Range = require 'range'
{Range} = require 'telepath'
describe "UndoManager", ->
[buffer, undoManager] = []

View File

@@ -7,7 +7,7 @@ $ = jQuery = require 'jquery'
_ = require 'underscore'
Keymap = require 'keymap'
Config = require 'config'
Point = require 'point'
{Point} = require 'telepath'
Project = require 'project'
Directory = require 'directory'
File = require 'file'

View File

@@ -1,6 +1,5 @@
_ = require 'underscore'
Point = require 'point'
Range = require 'range'
{Point, Range} = require 'telepath'
EventEmitter = require 'event-emitter'
module.exports =

View File

@@ -1,6 +1,5 @@
{View} = require 'space-pen'
Point = require 'point'
Range = require 'range'
{Point, Range} = require 'telepath'
_ = require 'underscore'
### Internal ###

View File

@@ -1,5 +1,4 @@
Point = require 'point'
Range = require 'range'
{Point, Range} = require 'telepath'
EventEmitter = require 'event-emitter'
_ = require 'underscore'

View File

@@ -1,4 +1,4 @@
Range = require 'range'
{Range} = require 'telepath'
_ = require 'underscore'
EventEmitter = require 'event-emitter'
Subscriber = require 'subscriber'

View File

@@ -1,9 +1,8 @@
_ = require 'underscore'
TokenizedBuffer = require 'tokenized-buffer'
RowMap = require 'row-map'
Point = require 'point'
EventEmitter = require 'event-emitter'
Range = require 'range'
{Point, Range} = require 'telepath'
Fold = require 'fold'
Token = require 'token'
DisplayBufferMarker = require 'display-buffer-marker'

View File

@@ -2,7 +2,7 @@ _ = require 'underscore'
fsUtils = require 'fs-utils'
path = require 'path'
telepath = require 'telepath'
Point = require 'point'
{Point, Range} = telepath
Buffer = require 'text-buffer'
LanguageMode = require 'language-mode'
DisplayBuffer = require 'display-buffer'
@@ -10,7 +10,6 @@ Cursor = require 'cursor'
Selection = require 'selection'
EventEmitter = require 'event-emitter'
Subscriber = require 'subscriber'
Range = require 'range'
TextMateScopeSelector = require 'text-mate-scope-selector'
# An `EditSession` manages the states between {Editor}s, {Buffer}s, and the project as a whole.

View File

@@ -1,8 +1,7 @@
{View, $$} = require 'space-pen'
Buffer = require 'text-buffer'
Gutter = require 'gutter'
Point = require 'point'
Range = require 'range'
{Point, Range} = require 'telepath'
EditSession = require 'edit-session'
CursorView = require 'cursor-view'
SelectionView = require 'selection-view'

View File

@@ -1,5 +1,4 @@
Range = require 'range'
Point = require 'point'
{Point, Range} = require 'telepath'
# Public: Represents a fold that collapses multiple buffer lines into a single
# line on the screen.

View File

@@ -1,5 +1,5 @@
{View, $$, $$$} = require 'space-pen'
Range = require 'range'
{Range} = require 'telepath'
$ = require 'jquery'
_ = require 'underscore'

View File

@@ -1,4 +1,4 @@
Range = require 'range'
{Range} = require 'telepath'
_ = require 'underscore'
require 'underscore-extensions'
{OnigRegExp} = require 'oniguruma'

View File

@@ -1,182 +0,0 @@
_ = require 'underscore'
# Public: Represents a coordinate in the editor.
#
# Each `Point` is actually an object with two properties: `row` and `column`.
module.exports =
class Point
# Constructs a `Point` from a given object.
#
# object - This can be an {Array} (`[startRow, startColumn, endRow, endColumn]`) or an object `{row, column}`
#
# Returns the new {Point}.
@fromObject: (object) ->
if object instanceof Point
object
else
if _.isArray(object)
[row, column] = object
else
{ row, column } = object
new Point(row, column)
# Identifies which `Point` is smaller.
#
# "Smaller" means that both the `row` and `column` values of one `Point` are less than or equal
# to the other.
#
# point1 - The first {Point} to check
# point2 - The second {Point} to check
#
# Returns the smaller {Point}.
@min: (point1, point2) ->
point1 = @fromObject(point1)
point2 = @fromObject(point2)
if point1.isLessThanOrEqual(point2)
point1
else
point2
# Creates a new `Point` object.
#
# row - A {Number} indicating the row (default: 0)
# column - A {Number} indicating the column (default: 0)
#
# Returns a {Point},
constructor: (@row=0, @column=0) ->
# Creates an identical copy of the `Point`.
#
# Returns a duplicate {Point}.
copy: ->
new Point(@row, @column)
# Adds the `column`s of two `Point`s together.
#
# other - The {Point} to add with
#
# Returns the new {Point}.
add: (other) ->
other = Point.fromObject(other)
row = @row + other.row
if other.row == 0
column = @column + other.column
else
column = other.column
new Point(row, column)
# Moves a `Point`.
#
# In other words, the `row` values and `column` values are added to each other.
#
# other - The {Point} to add with
#
# Returns the new {Point}.
translate: (other) ->
other = Point.fromObject(other)
new Point(@row + other.row, @column + other.column)
# Creates two new `Point`s, split down a `column` value.
#
# In other words, given a point, this creates `Point(0, column)` and `Point(row, column)`.
#
# column - The {Number} to split at
#
# Returns an {Array} of two {Point}s.
splitAt: (column) ->
if @row == 0
rightColumn = @column - column
else
rightColumn = @column
[new Point(0, column), new Point(@row, rightColumn)]
# Compares two `Point`s.
#
# other - The {Point} to compare against
#
# Returns a {Number} matching the following rules:
# * If the first `row` is greater than `other.row`, returns `1`.
# * If the first `row` is less than `other.row`, returns `-1`.
# * If the first `column` is greater than `other.column`, returns `1`.
# * If the first `column` is less than `other.column`, returns `-1`.
#
# Otherwise, returns `0`.
compare: (other) ->
if @row > other.row
1
else if @row < other.row
-1
else
if @column > other.column
1
else if @column < other.column
-1
else
0
# Identifies if two `Point`s are equal.
#
# other - The {Point} to compare against
#
# Returns a {Boolean}.
isEqual: (other) ->
return false unless other
other = Point.fromObject(other)
@row == other.row and @column == other.column
# Identifies if one `Point` is less than another.
#
# other - The {Point} to compare against
#
# Returns a {Boolean}.
isLessThan: (other) ->
@compare(other) < 0
# Identifies if one `Point` is less than or equal to another.
#
# other - The {Point} to compare against
#
# Returns a {Boolean}.
isLessThanOrEqual: (other) ->
@compare(other) <= 0
# Identifies if one `Point` is greater than another.
#
# other - The {Point} to compare against
#
# Returns a {Boolean}.
isGreaterThan: (other) ->
@compare(other) > 0
# Identifies if one `Point` is greater than or equal to another.
#
# other - The {Point} to compare against
#
# Returns a {Boolean}.
isGreaterThanOrEqual: (other) ->
@compare(other) >= 0
# Converts the {Point} to a String.
#
# Returns a {String}.
toString: ->
"#{@row},#{@column}"
# Converts the {Point} to an Array.
#
# Returns an {Array}.
toArray: ->
[@row, @column]
### Internal ###
inspect: ->
"(#{@row}, #{@column})"
# Internal:
serialize: ->
@toArray()

View File

@@ -3,7 +3,7 @@ path = require 'path'
_ = require 'underscore'
$ = require 'jquery'
telepath = require 'telepath'
Range = require 'range'
{Range} = telepath
Buffer = require 'text-buffer'
EditSession = require 'edit-session'
EventEmitter = require 'event-emitter'

View File

@@ -1,216 +0,0 @@
Point = require 'point'
_ = require 'underscore'
# Public: Indicates a region within the editor.
#
# To better visualize how this works, imagine a rectangle.
# Each quadrant of the rectangle is analogus to a range, as ranges contain a
# starting row and a starting column, as well as an ending row, and an ending column.
#
# Each `Range` is actually constructed of two `Point` objects, labelled `start` and `end`.
module.exports =
class Range
# Constructs a `Range` from a given object.
#
# object - This can be an {Array} (`[startRow, startColumn, endRow, endColumn]`) or an object `{start: Point, end: Point}`
#
# Returns the new {Range}.
@fromObject: (object) ->
if _.isArray(object)
new Range(object...)
else if object instanceof Range
object
else
new Range(object.start, object.end)
# Constructs a `Range` from a {Point}, and the delta values beyond that point.
#
# point - A {Point} to start with
# rowDelta - A {Number} indicating how far from the starting {Point} the range's row should be
# columnDelta - A {Number} indicating how far from the starting {Point} the range's column should be
#
# Returns the new {Range}.
@fromPointWithDelta: (point, rowDelta, columnDelta) ->
pointA = Point.fromObject(point)
pointB = new Point(point.row + rowDelta, point.column + columnDelta)
new Range(pointA, pointB)
# Creates a new `Range` object based on two {Point}s.
#
# pointA - The first {Point} (default: `0, 0`)
# pointB - The second {Point} (default: `0, 0`)
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
# Creates an identical copy of the `Range`.
#
# Returns a duplicate {Range}.
copy: ->
new Range(@start.copy(), @end.copy())
# Identifies if two `Range`s are equal.
#
# All four points (`start.row`, `start.column`, `end.row`, `end.column`) must be
# equal for this method to return `true`.
#
# other - A different {Range} to check against
#
# Returns a {Boolean}.
isEqual: (other) ->
if _.isArray(other) and other.length == 2
other = new Range(other...)
other.start.isEqual(@start) and other.end.isEqual(@end)
# Returns an integer (-1, 0, 1) indicating whether this range is less than, equal,
# or greater than the given range when sorting.
#
# Ranges that start earlier are considered "less than" ranges that start later.
# If ranges start at the same location, the larger range sorts before the smaller
# range.
#
# other - A {Range} to compare against.
#
# Returns a {Number}, either -1, 0, or 1.
compare: (other) ->
other = Range.fromObject(other)
if value = @start.compare(other.start)
value
else
other.end.compare(@end)
# Identifies if the `Range` is on the same line.
#
# In other words, if `start.row` is equal to `end.row`.
#
# Returns a {Boolean}.
isSingleLine: ->
@start.row == @end.row
# Identifies if two `Range`s are on the same line.
#
# other - A different {Range} to check against
#
# Returns a {Boolean}.
coversSameRows: (other) ->
@start.row == other.start.row && @end.row == other.end.row
# Adds a new point to the `Range`s `start` and `end`.
#
# point - A new {Point} to add
#
# Returns the new {Range}.
add: (point) ->
new Range(@start.add(point), @end.add(point))
# Moves a `Range`.
#
# In other words, the starting and ending `row` values, and the starting and ending
# `column` values, are added to each other.
#
# startPoint - The {Point} to move the `Range`s `start` by
# endPoint - The {Point} to move the `Range`s `end` by
#
# Returns the new {Range}.
translate: (startPoint, endPoint=startPoint) ->
new Range(@start.translate(startPoint), @end.translate(endPoint))
# Identifies if two `Range`s intersect each other.
#
# otherRange - A different {Range} to check against
#
# Returns a {Boolean}.
intersectsWith: (otherRange) ->
if @start.isLessThanOrEqual(otherRange.start)
@end.isGreaterThanOrEqual(otherRange.start)
else
otherRange.intersectsWith(this)
# Identifies if a second `Range` is contained within a first.
#
# otherRange - A different {Range} to check against
# options - A hash with a single option:
# exclusive: A {Boolean} which, if `true`, indicates that no {Point}s in the `Range` can be equal
#
# Returns a {Boolean}.
containsRange: (otherRange, {exclusive} = {}) ->
{ start, end } = Range.fromObject(otherRange)
@containsPoint(start, {exclusive}) and @containsPoint(end, {exclusive})
# Identifies if a `Range` contains a {Point}.
#
# point - A {Point} to check against
# options - A hash with a single option:
# exclusive: A {Boolean} which, if `true`, indicates that no {Point}s in the `Range` can be equal
#
# Returns a {Boolean}.
containsPoint: (point, {exclusive} = {}) ->
point = Point.fromObject(point)
if exclusive
point.isGreaterThan(@start) and point.isLessThan(@end)
else
point.isGreaterThanOrEqual(@start) and point.isLessThanOrEqual(@end)
# Identifies if a `Range` contains a row.
#
# row - A row {Number} to check against
# options - A hash with a single option:
#
# Returns a {Boolean}.
containsRow: (row) ->
@start.row <= row <= @end.row
# Constructs a union between two `Range`s.
#
# otherRange - A different {Range} to unionize with
#
# Returns the new {Range}.
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)
# Identifies if a `Range` is empty.
#
# A `Range` is empty if its start {Point} matches its end.
#
# Returns a {Boolean}.
isEmpty: ->
@start.isEqual(@end)
# Calculates the difference between a `Range`s `start` and `end` points.
#
# Returns a {Point}.
toDelta: ->
rows = @end.row - @start.row
if rows == 0
columns = @end.column - @start.column
else
columns = @end.column
new Point(rows, columns)
# Calculates the number of rows a `Range`s contains.
#
# Returns a {Number}.
getRowCount: ->
@end.row - @start.row + 1
# Returns an array of all rows in a `Range`
#
# Returns an {Array}
getRows: ->
[@start.row..@end.row]
### Internal ###
inspect: ->
"[#{@start.inspect()} - #{@end.inspect()}]"

View File

@@ -1,5 +1,4 @@
Point = require 'point'
Range = require 'range'
{Point, Range} = require 'telepath'
{View, $$} = require 'space-pen'
# Internal:

View File

@@ -1,4 +1,4 @@
Range = require 'range'
{Range} = require 'telepath'
EventEmitter = require 'event-emitter'
_ = require 'underscore'

View File

@@ -1,9 +1,8 @@
_ = require 'underscore'
telepath = require 'telepath'
{Point, Range} = telepath
fsUtils = require 'fs-utils'
File = require 'file'
Point = require 'point'
Range = require 'range'
EventEmitter = require 'event-emitter'
UndoManager = require 'undo-manager'
BufferChangeOperation = require 'buffer-change-operation'

View File

@@ -3,8 +3,7 @@ TokenizedLine = require 'tokenized-line'
EventEmitter = require 'event-emitter'
Subscriber = require 'subscriber'
Token = require 'token'
Range = require 'range'
Point = require 'point'
{Point, Range} = require 'telepath'
### Internal ###

View File

@@ -1,6 +1,6 @@
$ = require 'jquery'
{$$} = require 'space-pen'
Range = require 'range'
{Range} = require 'telepath'
SelectList = require 'select-list'
module.exports =

View File

@@ -1,6 +1,6 @@
_ = require 'underscore'
{$$} = require 'space-pen'
Range = require 'range'
{Range} = require 'telepath'
module.exports =
pairedCharacters:

View File

@@ -1,7 +1,6 @@
{View} = require 'space-pen'
Editor = require 'editor'
$ = require 'jquery'
Point = require 'point'
_ = require 'underscore'
Guid = require 'guid'

View File

@@ -1,5 +1,5 @@
Address = require 'command-panel/lib/commands/address'
Range = require 'range'
{Range} = require 'telepath'
module.exports =
class AddressRange extends Address

View File

@@ -1,5 +1,5 @@
Address = require './address'
Range = require 'range'
{Range} = require 'telepath'
module.exports =
class EofAddress extends Address

View File

@@ -1,5 +1,5 @@
Address = require './address'
Range = require 'range'
{Range} = require 'telepath'
module.exports =
class LineAddress extends Address

View File

@@ -1,5 +1,5 @@
Address = require './address'
Range = require 'range'
{Range} = require 'telepath'
module.exports =
class RegexAddress extends Address

View File

@@ -1,5 +1,5 @@
Address = require './address'
Range = require 'range'
{Range} = require 'telepath'
module.exports =
class ZeroAddress extends Address

View File

@@ -6,7 +6,7 @@ humanize = require 'humanize-plus'
fsUtils = require 'fs-utils'
path = require 'path'
PathLoader = require './path-loader'
Point = require 'point'
{Point} = require 'telepath'
module.exports =
class FuzzyFinderView extends SelectList

View File

@@ -1,7 +1,7 @@
{View} = require 'space-pen'
Editor = require 'editor'
$ = require 'jquery'
Point = require 'point'
{Point} = require 'telepath'
module.exports =
class GoToLineView extends View

View File

@@ -1,5 +1,5 @@
_ = require 'underscore'
Range = require 'range'
{Range} = require 'telepath'
module.exports =
class Snippet

View File

@@ -1,5 +1,5 @@
{$$} = require 'space-pen'
Range = require 'range'
{Range} = require 'telepath'
SelectList = require 'select-list'
module.exports =

View File

@@ -1,5 +1,5 @@
{View} = require 'space-pen'
Range = require 'range'
{Range} = require 'telepath'
CorrectionsView = require './corrections-view'
module.exports =

View File

@@ -2,7 +2,7 @@
SelectList = require 'select-list'
TagGenerator = require './tag-generator'
TagReader = require './tag-reader'
Point = require 'point'
{Point} = require 'telepath'
fsUtils = require 'fs-utils'
path = require 'path'
$ = require 'jquery'

View File

@@ -1,4 +1,4 @@
Point = require 'point'
{Point} = require 'telepath'
$ = require 'jquery'
BufferedProcess = require 'buffered-process'
fsUtils = require 'fs-utils'