Merge master

This commit is contained in:
Garen Torikian 2012-04-09 21:33:39 -07:00
commit 1c5320f84e
406 changed files with 82454 additions and 34265 deletions

View file

@ -83,7 +83,7 @@ var Document = function(text) {
*
* Replaces all the lines in the current `Document` with the value of `text`.
**/
this.setValue = function(text) {
this.setValue = function(text) {
var len = this.getLength();
this.remove(new Range(0, 0, len, this.getLine(len-1).length));
this.insert({row: 0, column:0}, text);
@ -94,7 +94,7 @@ var Document = function(text) {
*
* Returns all the lines in the document as a single string, split by the new line character.
**/
this.getValue = function() {
this.getValue = function() {
return this.getAllLines().join(this.getNewLineCharacter());
};
@ -105,7 +105,7 @@ var Document = function(text) {
*
* Creates a new `Anchor` to define a floating point in the document.
**/
this.createAnchor = function(row, column) {
this.createAnchor = function(row, column) {
return new Anchor(this, row, column);
};
@ -137,7 +137,7 @@ var Document = function(text) {
*
*
**/
this.$detectNewLine = function(text) {
this.$detectNewLine = function(text) {
var match = text.match(/^.*?(\r\n|\r|\n)/m);
if (match) {
this.$autoNewLine = match[1];
@ -159,7 +159,7 @@ var Document = function(text) {
*
*
**/
this.getNewLineCharacter = function() {
this.getNewLineCharacter = function() {
switch (this.$newLineMode) {
case "windows":
return "\r\n";
@ -180,7 +180,7 @@ var Document = function(text) {
*
* [Sets the new line mode.]{: #Document.setNewLineMode.desc}
**/
this.setNewLineMode = function(newLineMode) {
this.setNewLineMode = function(newLineMode) {
if (this.$newLineMode === newLineMode)
return;
@ -193,7 +193,7 @@ var Document = function(text) {
* [Returns the type of newlines being used; either `windows`, `unix`, or `auto`]{: #Document.getNewLineMode}
*
**/
this.getNewLineMode = function() {
this.getNewLineMode = function() {
return this.$newLineMode;
};
@ -204,7 +204,7 @@ var Document = function(text) {
* Returns `true` if `text` is a newline character (either `\r\n`, `\r`, or `\n`).
*
**/
this.isNewLine = function(text) {
this.isNewLine = function(text) {
return (text == "\r\n" || text == "\r" || text == "\n");
};
@ -215,7 +215,7 @@ var Document = function(text) {
* Returns a verbatim copy of the given line as it is in the document
*
**/
this.getLine = function(row) {
this.getLine = function(row) {
return this.$lines[row] || "";
};
@ -227,7 +227,7 @@ var Document = function(text) {
* Returns an array of strings of the rows between `firstRow` and `lastRow`. This function is inclusive of `lastRow`.
*
**/
this.getLines = function(firstRow, lastRow) {
this.getLines = function(firstRow, lastRow) {
return this.$lines.slice(firstRow, lastRow + 1);
};
@ -236,7 +236,7 @@ var Document = function(text) {
*
* Returns all lines in the document as string array. <Warning>The caller should not modify this array!</Warning>
**/
this.getAllLines = function() {
this.getAllLines = function() {
return this.getLines(0, this.getLength());
};
@ -245,7 +245,7 @@ var Document = function(text) {
*
* Returns the number of rows in the document.
**/
this.getLength = function() {
this.getLength = function() {
return this.$lines.length;
};
@ -255,7 +255,7 @@ var Document = function(text) {
*
* [Given a range within the document, this function returns all the text within that range as a single string.]{: #Document.getTextRange.desc}
**/
this.getTextRange = function(range) {
this.getTextRange = function(range) {
if (range.start.row == range.end.row) {
return this.$lines[range.start.row].substring(range.start.column,
range.end.column);
@ -274,7 +274,7 @@ var Document = function(text) {
*
*
**/
this.$clipPosition = function(position) {
this.$clipPosition = function(position) {
var length = this.getLength();
if (position.row >= length) {
position.row = Math.max(0, length - 1);
@ -295,12 +295,13 @@ var Document = function(text) {
* Returns the position of the last line of `text`. If the length of `text` is 0, this function simply returns `position`.
*
**/
this.insert = function(position, text) {
if (text.length == 0)
this.insert = function(position, text) {
if (!text || text.length === 0)
return position;
position = this.$clipPosition(position);
// only detect new lines if the document has no line break yet
if (this.getLength() <= 1)
this.$detectNewLine(text);
@ -335,7 +336,7 @@ var Document = function(text) {
* {row: row, column: 0}
*
**/
this.insertLines = function(row, lines) {
this.insertLines = function(row, lines) {
if (lines.length == 0)
return {row: row, column: 0};
@ -366,7 +367,7 @@ var Document = function(text) {
* {row: endRow, column: 0}
*
**/
this.insertNewLine = function(position) {
this.insertNewLine = function(position) {
position = this.$clipPosition(position);
var line = this.$lines[position.row] || "";
@ -404,7 +405,7 @@ var Document = function(text) {
* If `text` is empty, this function returns the value of `position`.
*
**/
this.insertInLine = function(position, text) {
this.insertInLine = function(position, text) {
if (text.length == 0)
return position;
@ -438,7 +439,7 @@ var Document = function(text) {
*
* Returns the new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`.
**/
this.remove = function(range) {
this.remove = function(range) {
// clip to document
range.start = this.$clipPosition(range.start);
range.end = this.$clipPosition(range.end);
@ -482,7 +483,7 @@ var Document = function(text) {
*
* Returns an object containing `startRow` and `startColumn`, indicating the new row and column values. If `startColumn` is equal to `endColumn`, this function returns nothing.
**/
this.removeInLine = function(row, startColumn, endColumn) {
this.removeInLine = function(row, startColumn, endColumn) {
if (startColumn == endColumn)
return;
@ -507,14 +508,14 @@ var Document = function(text) {
* - lastRow (Number): The last row to be removed
*
* Removes a range of full lines. This method also triggers the `'change'` event.
*
*
*
* #### Returns
*
* Returns all the removed lines.
*
**/
this.removeLines = function(firstRow, lastRow) {
this.removeLines = function(firstRow, lastRow) {
var range = new Range(firstRow, 0, lastRow + 1, 0);
var removed = this.$lines.splice(firstRow, lastRow - firstRow + 1);
@ -535,7 +536,7 @@ var Document = function(text) {
* Removes the new line between `row` and the row immediately following it. This method also triggers the `'change'` event.
*
**/
this.removeNewLine = function(row) {
this.removeNewLine = function(row) {
var firstLine = this.getLine(row);
var secondLine = this.getLine(row+1);
@ -570,7 +571,7 @@ var Document = function(text) {
* If the text is the exact same as what currently exists, this function returns an object containing the current `range.end` value.
*
**/
this.replace = function(range, text) {
this.replace = function(range, text) {
if (text.length == 0 && range.isEmpty())
return range.start;
@ -595,7 +596,7 @@ var Document = function(text) {
*
* Applies all the changes previously accumulated. These can be either `'includeText'`, `'insertLines'`, `'removeText'`, and `'removeLines'`.
**/
this.applyDeltas = function(deltas) {
this.applyDeltas = function(deltas) {
for (var i=0; i<deltas.length; i++) {
var delta = deltas[i];
var range = Range.fromPoints(delta.range.start, delta.range.end);
@ -616,7 +617,7 @@ var Document = function(text) {
*
* Reverts any changes previously applied. These can be either `'includeText'`, `'insertLines'`, `'removeText'`, and `'removeLines'`.
**/
this.revertDeltas = function(deltas) {
this.revertDeltas = function(deltas) {
for (var i=deltas.length-1; i>=0; i--) {
var delta = deltas[i];