cleanup
This commit is contained in:
parent
a9dbdaebb4
commit
7eeb988f87
3 changed files with 75 additions and 111 deletions
|
|
@ -192,13 +192,13 @@ function FoldLine(foldData, folds) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.split = function(row, column) {
|
this.split = function(row, column) {
|
||||||
var fold = this.getNextFoldTo(row, column).fold,
|
var fold = this.getNextFoldTo(row, column).fold;
|
||||||
folds = this.folds;
|
var folds = this.folds;
|
||||||
var foldData = this.foldData;
|
var foldData = this.foldData;
|
||||||
|
|
||||||
if (!fold) {
|
if (!fold)
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
var i = folds.indexOf(fold);
|
var i = folds.indexOf(fold);
|
||||||
var foldBefore = folds[i - 1];
|
var foldBefore = folds[i - 1];
|
||||||
this.end.row = foldBefore.end.row;
|
this.end.row = foldBefore.end.row;
|
||||||
|
|
|
||||||
163
lib/ace/range.js
163
lib/ace/range.js
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010, Ajax.org B.V.
|
* Copyright (c) 2010, Ajax.org B.V.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* * Neither the name of Ajax.org B.V. nor the
|
* * Neither the name of Ajax.org B.V. nor the
|
||||||
* names of its contributors may be used to endorse or promote products
|
* names of its contributors may be used to endorse or promote products
|
||||||
* derived from this software without specific prior written permission.
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
|
@ -30,10 +30,10 @@
|
||||||
|
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
var comparePoints = function(p1, p2) {
|
||||||
|
return p1.row - p2.row || p1.column - p2.column;
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
*
|
|
||||||
* This object is used in various places to indicate 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 starting column, and an ending row, and ending column.
|
* This object is used in various places to indicate 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 starting column, and an ending row, and ending column.
|
||||||
* @class Range
|
* @class Range
|
||||||
**/
|
**/
|
||||||
|
|
@ -45,7 +45,6 @@ define(function(require, exports, module) {
|
||||||
* @param {Number} endRow The ending row
|
* @param {Number} endRow The ending row
|
||||||
* @param {Number} endColumn The ending column
|
* @param {Number} endColumn The ending column
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @constructor
|
* @constructor
|
||||||
**/
|
**/
|
||||||
var Range = function(startRow, startColumn, endRow, endColumn) {
|
var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
|
|
@ -65,30 +64,29 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
* Returns `true` if and only if the starting row and column, and ending row and column, are equivalent to those given by `range`.
|
* Returns `true` if and only if the starting row and column, and ending row and column, are equivalent to those given by `range`.
|
||||||
* @param {Range} range A range to check against
|
* @param {Range} range A range to check against
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
**/
|
**/
|
||||||
this.isEqual = function(range) {
|
this.isEqual = function(range) {
|
||||||
return this.start.row == range.start.row &&
|
return this.start.row === range.start.row &&
|
||||||
this.end.row == range.end.row &&
|
this.end.row === range.end.row &&
|
||||||
this.start.column == range.start.column &&
|
this.start.column === range.start.column &&
|
||||||
this.end.column == range.end.column
|
this.end.column === range.end.column;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Returns a string containing the range's row and column information, given like this:
|
* Returns a string containing the range's row and column information, given like this:
|
||||||
* ```
|
* ```
|
||||||
* [start.row/start.column] -> [end.row/end.column]
|
* [start.row/start.column] -> [end.row/end.column]
|
||||||
* ```
|
* ```
|
||||||
* @return {String}
|
* @return {String}
|
||||||
**/
|
**/
|
||||||
this.toString = function() {
|
this.toString = function() {
|
||||||
return ("Range: [" + this.start.row + "/" + this.start.column +
|
return ("Range: [" + this.start.row + "/" + this.start.column +
|
||||||
"] -> [" + this.end.row + "/" + this.end.column + "]");
|
"] -> [" + this.end.row + "/" + this.end.column + "]");
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Returns `true` if the `row` and `column` provided are within the given range. This can better be expressed as returning `true` if:
|
* Returns `true` if the `row` and `column` provided are within the given range. This can better be expressed as returning `true` if:
|
||||||
* ```javascript
|
* ```javascript
|
||||||
|
|
@ -99,17 +97,16 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
* @param {Number} column A column to check for
|
* @param {Number} column A column to check for
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
* @related Range.compare
|
* @related Range.compare
|
||||||
**/
|
**/
|
||||||
|
|
||||||
this.contains = function(row, column) {
|
this.contains = function(row, column) {
|
||||||
return this.compare(row, column) == 0;
|
return this.compare(row, column) == 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares `this` range (A) with another range (B).
|
* Compares `this` range (A) with another range (B).
|
||||||
* @param {Range} range A range to compare with
|
* @param {Range} range A range to compare with
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @related Range.compare
|
* @related Range.compare
|
||||||
* @returns {Number} This method returns one of the following numbers:<br/>
|
* @returns {Number} This method returns one of the following numbers:<br/>
|
||||||
* <br/>
|
* <br/>
|
||||||
|
|
@ -119,7 +116,7 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
* * `+1`: (B) begins inside of (A) but ends outside of (A)<br/>
|
* * `+1`: (B) begins inside of (A) but ends outside of (A)<br/>
|
||||||
* * `+2`: (B) is after (A) and doesn't intersect with (A)<br/>
|
* * `+2`: (B) is after (A) and doesn't intersect with (A)<br/>
|
||||||
* * `42`: FTW state: (B) ends in (A) but starts outside of (A)
|
* * `42`: FTW state: (B) ends in (A) but starts outside of (A)
|
||||||
**/
|
**/
|
||||||
this.compareRange = function(range) {
|
this.compareRange = function(range) {
|
||||||
var cmp,
|
var cmp,
|
||||||
end = range.end,
|
end = range.end,
|
||||||
|
|
@ -149,12 +146,11 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Checks the row and column points of `p` with the row and column points of the calling range.
|
* Checks the row and column points of `p` with the row and column points of the calling range.
|
||||||
*
|
*
|
||||||
* @param {Range} p A point to compare with
|
* @param {Range} p A point to compare with
|
||||||
*
|
*
|
||||||
* @related Range.compare
|
* @related Range.compare
|
||||||
* @returns {Number} This method returns one of the following numbers:<br/>
|
* @returns {Number} This method returns one of the following numbers:<br/>
|
||||||
* * `0` if the two points are exactly equal<br/>
|
* * `0` if the two points are exactly equal<br/>
|
||||||
|
|
@ -168,19 +164,18 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
* If the ending row of the calling range is equal to `p.row`, and:<br/>
|
* If the ending row of the calling range is equal to `p.row`, and:<br/>
|
||||||
* * `p.column` is less than or equal to the calling range's ending column, this returns `0`<br/>
|
* * `p.column` is less than or equal to the calling range's ending column, this returns `0`<br/>
|
||||||
* * Otherwise, it returns 1<br/>
|
* * Otherwise, it returns 1<br/>
|
||||||
**/
|
**/
|
||||||
this.comparePoint = function(p) {
|
this.comparePoint = function(p) {
|
||||||
return this.compare(p.row, p.column);
|
return this.compare(p.row, p.column);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the start and end points of `range` and compares them to the calling range. Returns `true` if the `range` is contained within the caller's range.
|
* Checks the start and end points of `range` and compares them to the calling range. Returns `true` if the `range` is contained within the caller's range.
|
||||||
* @param {Range} range A range to compare with
|
* @param {Range} range A range to compare with
|
||||||
*
|
*
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
* @related Range.comparePoint
|
* @related Range.comparePoint
|
||||||
*
|
**/
|
||||||
**/
|
|
||||||
this.containsRange = function(range) {
|
this.containsRange = function(range) {
|
||||||
return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
|
return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
|
||||||
};
|
};
|
||||||
|
|
@ -189,7 +184,6 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
* Returns `true` if passed in `range` intersects with the one calling this method.
|
* Returns `true` if passed in `range` intersects with the one calling this method.
|
||||||
* @param {Range} range A range to compare with
|
* @param {Range} range A range to compare with
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
**/
|
**/
|
||||||
this.intersects = function(range) {
|
this.intersects = function(range) {
|
||||||
|
|
@ -202,7 +196,6 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
* @param {Number} row A row point to compare with
|
* @param {Number} row A row point to compare with
|
||||||
* @param {Number} column A column point to compare with
|
* @param {Number} column A column point to compare with
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
**/
|
**/
|
||||||
this.isEnd = function(row, column) {
|
this.isEnd = function(row, column) {
|
||||||
|
|
@ -214,9 +207,8 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
* @param {Number} row A row point to compare with
|
* @param {Number} row A row point to compare with
|
||||||
* @param {Number} column A column point to compare with
|
* @param {Number} column A column point to compare with
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
**/
|
**/
|
||||||
this.isStart = function(row, column) {
|
this.isStart = function(row, column) {
|
||||||
return this.start.row == row && this.start.column == column;
|
return this.start.row == row && this.start.column == column;
|
||||||
};
|
};
|
||||||
|
|
@ -226,9 +218,7 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
* @param {Number} row A row point to set
|
* @param {Number} row A row point to set
|
||||||
* @param {Number} column A column point to set
|
* @param {Number} column A column point to set
|
||||||
*
|
*
|
||||||
*
|
**/
|
||||||
*
|
|
||||||
**/
|
|
||||||
this.setStart = function(row, column) {
|
this.setStart = function(row, column) {
|
||||||
if (typeof row == "object") {
|
if (typeof row == "object") {
|
||||||
this.start.column = row.column;
|
this.start.column = row.column;
|
||||||
|
|
@ -244,9 +234,7 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
* @param {Number} row A row point to set
|
* @param {Number} row A row point to set
|
||||||
* @param {Number} column A column point to set
|
* @param {Number} column A column point to set
|
||||||
*
|
*
|
||||||
*
|
**/
|
||||||
*
|
|
||||||
**/
|
|
||||||
this.setEnd = function(row, column) {
|
this.setEnd = function(row, column) {
|
||||||
if (typeof row == "object") {
|
if (typeof row == "object") {
|
||||||
this.end.column = row.column;
|
this.end.column = row.column;
|
||||||
|
|
@ -257,15 +245,15 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if the `row` and `column` are within the given range.
|
* Returns `true` if the `row` and `column` are within the given range.
|
||||||
* @param {Number} row A row point to compare with
|
* @param {Number} row A row point to compare with
|
||||||
* @param {Number} column A column point to compare with
|
* @param {Number} column A column point to compare with
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
* @related Range.compare
|
* @related Range.compare
|
||||||
**/
|
**/
|
||||||
this.inside = function(row, column) {
|
this.inside = function(row, column) {
|
||||||
if (this.compare(row, column) == 0) {
|
if (this.compare(row, column) == 0) {
|
||||||
if (this.isEnd(row, column) || this.isStart(row, column)) {
|
if (this.isEnd(row, column) || this.isStart(row, column)) {
|
||||||
|
|
@ -277,15 +265,14 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if the `row` and `column` are within the given range's starting points.
|
* Returns `true` if the `row` and `column` are within the given range's starting points.
|
||||||
* @param {Number} row A row point to compare with
|
* @param {Number} row A row point to compare with
|
||||||
* @param {Number} column A column point to compare with
|
* @param {Number} column A column point to compare with
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
* @related Range.compare
|
* @related Range.compare
|
||||||
**/
|
**/
|
||||||
this.insideStart = function(row, column) {
|
this.insideStart = function(row, column) {
|
||||||
if (this.compare(row, column) == 0) {
|
if (this.compare(row, column) == 0) {
|
||||||
if (this.isEnd(row, column)) {
|
if (this.isEnd(row, column)) {
|
||||||
|
|
@ -297,16 +284,15 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if the `row` and `column` are within the given range's ending points.
|
* Returns `true` if the `row` and `column` are within the given range's ending points.
|
||||||
* @param {Number} row A row point to compare with
|
* @param {Number} row A row point to compare with
|
||||||
* @param {Number} column A column point to compare with
|
* @param {Number} column A column point to compare with
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
* @related Range.compare
|
* @related Range.compare
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
this.insideEnd = function(row, column) {
|
this.insideEnd = function(row, column) {
|
||||||
if (this.compare(row, column) == 0) {
|
if (this.compare(row, column) == 0) {
|
||||||
if (this.isStart(row, column)) {
|
if (this.isStart(row, column)) {
|
||||||
|
|
@ -318,11 +304,11 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the row and column points with the row and column points of the calling range.
|
* Checks the row and column points with the row and column points of the calling range.
|
||||||
* @param {Number} row A row point to compare with
|
* @param {Number} row A row point to compare with
|
||||||
* @param {Number} column A column point to compare with
|
* @param {Number} column A column point to compare with
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @returns {Number} This method returns one of the following numbers:<br/>
|
* @returns {Number} This method returns one of the following numbers:<br/>
|
||||||
* `0` if the two points are exactly equal <br/>
|
* `0` if the two points are exactly equal <br/>
|
||||||
|
|
@ -363,8 +349,6 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
* Checks the row and column points with the row and column points of the calling range.
|
* Checks the row and column points with the row and column points of the calling range.
|
||||||
* @param {Number} row A row point to compare with
|
* @param {Number} row A row point to compare with
|
||||||
* @param {Number} column A column point to compare with
|
* @param {Number} column A column point to compare with
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
*
|
||||||
* @returns {Number} This method returns one of the following numbers:<br/>
|
* @returns {Number} This method returns one of the following numbers:<br/>
|
||||||
* <br/>
|
* <br/>
|
||||||
|
|
@ -393,7 +377,7 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
* Checks the row and column points with the row and column points of the calling range.
|
* Checks the row and column points with the row and column points of the calling range.
|
||||||
* @param {Number} row A row point to compare with
|
* @param {Number} row A row point to compare with
|
||||||
* @param {Number} column A column point to compare with
|
* @param {Number} column A column point to compare with
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @returns {Number} This method returns one of the following numbers:<br/>
|
* @returns {Number} This method returns one of the following numbers:<br/>
|
||||||
* `0` if the two points are exactly equal<br/>
|
* `0` if the two points are exactly equal<br/>
|
||||||
|
|
@ -416,11 +400,11 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the row and column points with the row and column points of the calling range.
|
* Checks the row and column points with the row and column points of the calling range.
|
||||||
* @param {Number} row A row point to compare with
|
* @param {Number} row A row point to compare with
|
||||||
* @param {Number} column A column point to compare with
|
* @param {Number} column A column point to compare with
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @returns {Number} This method returns one of the following numbers:<br/>
|
* @returns {Number} This method returns one of the following numbers:<br/>
|
||||||
* * `1` if the ending row of the calling range is equal to `row`, and the ending column of the calling range is equal to `column`<br/>
|
* * `1` if the ending row of the calling range is equal to `row`, and the ending column of the calling range is equal to `column`<br/>
|
||||||
|
|
@ -439,51 +423,34 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the part of the current `Range` that occurs within the boundaries of `firstRow` and `lastRow` as a new `Range` object.
|
* Returns the part of the current `Range` that occurs within the boundaries of `firstRow` and `lastRow` as a new `Range` object.
|
||||||
* @param {Number} firstRow The starting row
|
* @param {Number} firstRow The starting row
|
||||||
* @param {Number} lastRow The ending row
|
* @param {Number} lastRow The ending row
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @returns {Range}
|
* @returns {Range}
|
||||||
**/
|
**/
|
||||||
this.clipRows = function(firstRow, lastRow) {
|
this.clipRows = function(firstRow, lastRow) {
|
||||||
if (this.end.row > lastRow) {
|
if (this.end.row > lastRow)
|
||||||
var end = {
|
var end = {row: lastRow + 1, column: 0};
|
||||||
row: lastRow+1,
|
else if (this.end.row < firstRow)
|
||||||
column: 0
|
var end = {row: firstRow, column: 0};
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.start.row > lastRow) {
|
if (this.start.row > lastRow)
|
||||||
var start = {
|
var start = {row: lastRow + 1, column: 0};
|
||||||
row: lastRow+1,
|
else if (this.start.row < firstRow)
|
||||||
column: 0
|
var start = {row: firstRow, column: 0};
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.start.row < firstRow) {
|
|
||||||
var start = {
|
|
||||||
row: firstRow,
|
|
||||||
column: 0
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.end.row < firstRow) {
|
|
||||||
var end = {
|
|
||||||
row: firstRow,
|
|
||||||
column: 0
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return Range.fromPoints(start || this.start, end || this.end);
|
return Range.fromPoints(start || this.start, end || this.end);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes the row and column points for the calling range for both the starting and ending points.
|
* Changes the row and column points for the calling range for both the starting and ending points.
|
||||||
* @param {Number} row A new row to extend to
|
* @param {Number} row A new row to extend to
|
||||||
* @param {Number} column A new column to extend to
|
* @param {Number} column A new column to extend to
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @returns {Range} The original range with the new row
|
* @returns {Range} The original range with the new row
|
||||||
**/
|
**/
|
||||||
this.extend = function(row, column) {
|
this.extend = function(row, column) {
|
||||||
|
|
@ -500,11 +467,11 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.isEmpty = function() {
|
this.isEmpty = function() {
|
||||||
return (this.start.row == this.end.row && this.start.column == this.end.column);
|
return (this.start.row === this.end.row && this.start.column === this.end.column);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Returns `true` if the range spans across multiple lines.
|
* Returns `true` if the range spans across multiple lines.
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
**/
|
**/
|
||||||
|
|
@ -512,8 +479,8 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
return (this.start.row !== this.end.row);
|
return (this.start.row !== this.end.row);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Returns a duplicate of the calling range.
|
* Returns a duplicate of the calling range.
|
||||||
* @returns {Range}
|
* @returns {Range}
|
||||||
**/
|
**/
|
||||||
|
|
@ -521,7 +488,7 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
return Range.fromPoints(this.start, this.end);
|
return Range.fromPoints(this.start, this.end);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Returns a range containing the starting and ending rows of the original range, but with a column value of `0`.
|
* Returns a range containing the starting and ending rows of the original range, but with a column value of `0`.
|
||||||
* @returns {Range}
|
* @returns {Range}
|
||||||
|
|
@ -533,18 +500,16 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
return new Range(this.start.row, 0, this.end.row, 0)
|
return new Range(this.start.row, 0, this.end.row, 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given the current `Range`, this function converts those starting and ending points into screen positions, and then returns a new `Range` object.
|
* Given the current `Range`, this function converts those starting and ending points into screen positions, and then returns a new `Range` object.
|
||||||
* @param {EditSession} session The `EditSession` to retrieve coordinates from
|
* @param {EditSession} session The `EditSession` to retrieve coordinates from
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @returns {Range}
|
* @returns {Range}
|
||||||
**/
|
**/
|
||||||
this.toScreenRange = function(session) {
|
this.toScreenRange = function(session) {
|
||||||
var screenPosStart =
|
var screenPosStart = session.documentToScreenPosition(this.start);
|
||||||
session.documentToScreenPosition(this.start);
|
var screenPosEnd = session.documentToScreenPosition(this.end);
|
||||||
var screenPosEnd =
|
|
||||||
session.documentToScreenPosition(this.end);
|
|
||||||
|
|
||||||
return new Range(
|
return new Range(
|
||||||
screenPosStart.row, screenPosStart.column,
|
screenPosStart.row, screenPosStart.column,
|
||||||
|
|
@ -554,17 +519,17 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||||
|
|
||||||
}).call(Range.prototype);
|
}).call(Range.prototype);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and returns a new `Range` based on the row and column of the given parameters.
|
* Creates and returns a new `Range` based on the row and column of the given parameters.
|
||||||
* @param {Range} start A starting point to use
|
* @param {Range} start A starting point to use
|
||||||
* @param {Range} end An ending point to use
|
* @param {Range} end An ending point to use
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @returns {Range}
|
* @returns {Range}
|
||||||
**/
|
**/
|
||||||
Range.fromPoints = function(start, end) {
|
Range.fromPoints = function(start, end) {
|
||||||
return new Range(start.row, start.column, end.row, end.column);
|
return new Range(start.row, start.column, end.row, end.column);
|
||||||
};
|
};
|
||||||
|
Range.comparePoints = comparePoints;
|
||||||
|
|
||||||
exports.Range = Range;
|
exports.Range = Range;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -30,29 +30,28 @@
|
||||||
|
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
var Range = require("./range").Range;
|
||||||
|
var comparePoints = Range.comparePoints;
|
||||||
|
|
||||||
var RangeList = function() {
|
var RangeList = function() {
|
||||||
this.ranges = [];
|
this.ranges = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
this.comparePoints = function(p1, p2) {
|
this.comparePoints = comparePoints;
|
||||||
return p1.row - p2.row || p1.column - p2.column;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.pointIndex = function(pos, startIndex) {
|
this.pointIndex = function(pos, startIndex) {
|
||||||
var list = this.ranges;
|
var list = this.ranges;
|
||||||
|
|
||||||
for (var i = startIndex || 0; i < list.length; i++) {
|
for (var i = startIndex || 0; i < list.length; i++) {
|
||||||
var range = list[i];
|
var range = list[i];
|
||||||
var cmp = this.comparePoints(pos, range.end);
|
var cmp = comparePoints(pos, range.end);
|
||||||
|
|
||||||
if (cmp > 0)
|
if (cmp > 0)
|
||||||
continue;
|
continue;
|
||||||
if (cmp == 0)
|
if (cmp == 0)
|
||||||
return i;
|
return i;
|
||||||
cmp = this.comparePoints(pos, range.start);
|
cmp = comparePoints(pos, range.start);
|
||||||
if (cmp >= 0)
|
if (cmp >= 0)
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
|
|
@ -99,14 +98,14 @@ var RangeList = function() {
|
||||||
for (var i = 1; i < list.length; i++) {
|
for (var i = 1; i < list.length; i++) {
|
||||||
range = next;
|
range = next;
|
||||||
next = list[i];
|
next = list[i];
|
||||||
var cmp = this.comparePoints(range.end, next.start);
|
var cmp = comparePoints(range.end, next.start);
|
||||||
if (cmp < 0)
|
if (cmp < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (cmp == 0 && !(range.isEmpty() || next.isEmpty()))
|
if (cmp == 0 && !(range.isEmpty() || next.isEmpty()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (this.comparePoints(range.end, next.end) < 0) {
|
if (comparePoints(range.end, next.end) < 0) {
|
||||||
range.end.row = next.end.row;
|
range.end.row = next.end.row;
|
||||||
range.end.column = next.end.column;
|
range.end.column = next.end.column;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue