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) {
|
||||
var fold = this.getNextFoldTo(row, column).fold,
|
||||
folds = this.folds;
|
||||
var fold = this.getNextFoldTo(row, column).fold;
|
||||
var folds = this.folds;
|
||||
var foldData = this.foldData;
|
||||
|
||||
if (!fold) {
|
||||
if (!fold)
|
||||
return null;
|
||||
}
|
||||
|
||||
var i = folds.indexOf(fold);
|
||||
var foldBefore = folds[i - 1];
|
||||
this.end.row = foldBefore.end.row;
|
||||
|
|
|
|||
|
|
@ -30,10 +30,10 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
"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.
|
||||
* @class Range
|
||||
**/
|
||||
|
|
@ -45,7 +45,6 @@ define(function(require, exports, module) {
|
|||
* @param {Number} endRow The ending row
|
||||
* @param {Number} endColumn The ending column
|
||||
*
|
||||
*
|
||||
* @constructor
|
||||
**/
|
||||
var Range = function(startRow, startColumn, endRow, endColumn) {
|
||||
|
|
@ -65,14 +64,13 @@ 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`.
|
||||
* @param {Range} range A range to check against
|
||||
*
|
||||
*
|
||||
* @return {Boolean}
|
||||
**/
|
||||
this.isEqual = function(range) {
|
||||
return this.start.row == range.start.row &&
|
||||
this.end.row == range.end.row &&
|
||||
this.start.column == range.start.column &&
|
||||
this.end.column == range.end.column
|
||||
return this.start.row === range.start.row &&
|
||||
this.end.row === range.end.row &&
|
||||
this.start.column === range.start.column &&
|
||||
this.end.column === range.end.column;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -109,7 +107,6 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
|||
* Compares `this` range (A) with another range (B).
|
||||
* @param {Range} range A range to compare with
|
||||
*
|
||||
*
|
||||
* @related Range.compare
|
||||
* @returns {Number} This method returns one of the following numbers:<br/>
|
||||
* <br/>
|
||||
|
|
@ -150,7 +147,6 @@ 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.
|
||||
*
|
||||
* @param {Range} p A point to compare with
|
||||
|
|
@ -179,7 +175,6 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
|||
*
|
||||
* @returns {Boolean}
|
||||
* @related Range.comparePoint
|
||||
*
|
||||
**/
|
||||
this.containsRange = function(range) {
|
||||
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.
|
||||
* @param {Range} range A range to compare with
|
||||
*
|
||||
*
|
||||
* @returns {Boolean}
|
||||
**/
|
||||
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} column A column point to compare with
|
||||
*
|
||||
*
|
||||
* @returns {Boolean}
|
||||
**/
|
||||
this.isEnd = function(row, column) {
|
||||
|
|
@ -214,7 +207,6 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
|||
* @param {Number} row A row point to compare with
|
||||
* @param {Number} column A column point to compare with
|
||||
*
|
||||
*
|
||||
* @returns {Boolean}
|
||||
**/
|
||||
this.isStart = function(row, column) {
|
||||
|
|
@ -226,8 +218,6 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
|||
* @param {Number} row A row point to set
|
||||
* @param {Number} column A column point to set
|
||||
*
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.setStart = function(row, column) {
|
||||
if (typeof row == "object") {
|
||||
|
|
@ -244,8 +234,6 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
|||
* @param {Number} row A row point to set
|
||||
* @param {Number} column A column point to set
|
||||
*
|
||||
*
|
||||
*
|
||||
**/
|
||||
this.setEnd = function(row, column) {
|
||||
if (typeof row == "object") {
|
||||
|
|
@ -282,7 +270,6 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
|||
* @param {Number} row A row point to compare with
|
||||
* @param {Number} column A column point to compare with
|
||||
*
|
||||
*
|
||||
* @returns {Boolean}
|
||||
* @related Range.compare
|
||||
**/
|
||||
|
|
@ -302,7 +289,6 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
|||
* @param {Number} row A row point to compare with
|
||||
* @param {Number} column A column point to compare with
|
||||
*
|
||||
*
|
||||
* @returns {Boolean}
|
||||
* @related Range.compare
|
||||
*
|
||||
|
|
@ -364,8 +350,6 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
|||
* @param {Number} row A row point to compare with
|
||||
* @param {Number} column A column point to compare with
|
||||
*
|
||||
*
|
||||
*
|
||||
* @returns {Number} This method returns one of the following numbers:<br/>
|
||||
* <br/>
|
||||
* `0` if the two points are exactly equal<br/>
|
||||
|
|
@ -448,33 +432,16 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
|||
* @returns {Range}
|
||||
**/
|
||||
this.clipRows = function(firstRow, lastRow) {
|
||||
if (this.end.row > lastRow) {
|
||||
var end = {
|
||||
row: lastRow+1,
|
||||
column: 0
|
||||
};
|
||||
}
|
||||
if (this.end.row > lastRow)
|
||||
var end = {row: lastRow + 1, column: 0};
|
||||
else if (this.end.row < firstRow)
|
||||
var end = {row: firstRow, column: 0};
|
||||
|
||||
if (this.start.row > lastRow) {
|
||||
var start = {
|
||||
row: lastRow+1,
|
||||
column: 0
|
||||
};
|
||||
}
|
||||
if (this.start.row > lastRow)
|
||||
var start = {row: lastRow + 1, column: 0};
|
||||
else if (this.start.row < firstRow)
|
||||
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);
|
||||
};
|
||||
|
||||
|
|
@ -500,7 +467,7 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
|||
};
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -541,10 +508,8 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
|||
* @returns {Range}
|
||||
**/
|
||||
this.toScreenRange = function(session) {
|
||||
var screenPosStart =
|
||||
session.documentToScreenPosition(this.start);
|
||||
var screenPosEnd =
|
||||
session.documentToScreenPosition(this.end);
|
||||
var screenPosStart = session.documentToScreenPosition(this.start);
|
||||
var screenPosEnd = session.documentToScreenPosition(this.end);
|
||||
|
||||
return new Range(
|
||||
screenPosStart.row, screenPosStart.column,
|
||||
|
|
@ -559,12 +524,12 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
|||
* @param {Range} start A starting point to use
|
||||
* @param {Range} end An ending point to use
|
||||
*
|
||||
*
|
||||
* @returns {Range}
|
||||
**/
|
||||
Range.fromPoints = function(start, end) {
|
||||
return new Range(start.row, start.column, end.row, end.column);
|
||||
};
|
||||
Range.comparePoints = comparePoints;
|
||||
|
||||
exports.Range = Range;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -30,29 +30,28 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var Range = require("./range").Range;
|
||||
var comparePoints = Range.comparePoints;
|
||||
|
||||
var RangeList = function() {
|
||||
this.ranges = [];
|
||||
};
|
||||
|
||||
(function() {
|
||||
this.comparePoints = function(p1, p2) {
|
||||
return p1.row - p2.row || p1.column - p2.column;
|
||||
};
|
||||
this.comparePoints = comparePoints;
|
||||
|
||||
this.pointIndex = function(pos, startIndex) {
|
||||
var list = this.ranges;
|
||||
|
||||
for (var i = startIndex || 0; i < list.length; i++) {
|
||||
var range = list[i];
|
||||
var cmp = this.comparePoints(pos, range.end);
|
||||
var cmp = comparePoints(pos, range.end);
|
||||
|
||||
if (cmp > 0)
|
||||
continue;
|
||||
if (cmp == 0)
|
||||
return i;
|
||||
cmp = this.comparePoints(pos, range.start);
|
||||
cmp = comparePoints(pos, range.start);
|
||||
if (cmp >= 0)
|
||||
return i;
|
||||
|
||||
|
|
@ -99,14 +98,14 @@ var RangeList = function() {
|
|||
for (var i = 1; i < list.length; i++) {
|
||||
range = next;
|
||||
next = list[i];
|
||||
var cmp = this.comparePoints(range.end, next.start);
|
||||
var cmp = comparePoints(range.end, next.start);
|
||||
if (cmp < 0)
|
||||
continue;
|
||||
|
||||
if (cmp == 0 && !(range.isEmpty() || next.isEmpty()))
|
||||
continue;
|
||||
|
||||
if (this.comparePoints(range.end, next.end) < 0) {
|
||||
if (comparePoints(range.end, next.end) < 0) {
|
||||
range.end.row = next.end.row;
|
||||
range.end.column = next.end.column;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue