the document's lines array is no longer public

This commit is contained in:
Fabian Jakobs 2011-01-12 15:32:53 +01:00
commit ed9b0d4f0a
5 changed files with 45 additions and 44 deletions

View file

@ -47,7 +47,7 @@ var Range = require("ace/range").Range;
var Document = function(text, mode) {
this.modified = true;
this.lines = [];
this.$lines = [];
this.selection = new Selection(this);
this.$breakpoints = [];
@ -81,15 +81,15 @@ var Document = function(text, mode) {
};
this.setValue = function(text) {
var args = [0, this.lines.length];
var args = [0, this.$lines.length];
args.push.apply(args, this.$split(text));
this.lines.splice.apply(this.lines, args);
this.$lines.splice.apply(this.$lines, args);
this.modified = true;
this.fireChangeEvent(0);
};
this.toString = function() {
return this.lines.join(this.$getNewLineCharacter());
return this.$lines.join(this.$getNewLineCharacter());
};
this.getSelection = function() {
@ -306,7 +306,7 @@ var Document = function(text, mode) {
if (this.modified) {
this.modified = false;
var lines = this.lines;
var lines = this.$lines;
var longestLine = 0;
var longestScreenLine = 0;
var tabSize = this.getTabSize();
@ -330,7 +330,7 @@ var Document = function(text, mode) {
* Get a verbatim copy of the given line as it is in the document
*/
this.getLine = function(row) {
return this.lines[row] || "";
return this.$lines[row] || "";
};
/**
@ -338,27 +338,27 @@ var Document = function(text, mode) {
*/
this.getDisplayLine = function(row) {
var tab = new Array(this.getTabSize()+1).join(" ");
return this.lines[row].replace(/\t/g, tab);
return this.$lines[row].replace(/\t/g, tab);
};
this.getLines = function(firstRow, lastRow) {
return this.lines.slice(firstRow, lastRow+1);
return this.$lines.slice(firstRow, lastRow+1);
};
this.getLength = function() {
return this.lines.length;
return this.$lines.length;
};
this.getTextRange = function(range) {
if (range.start.row == range.end.row) {
return this.lines[range.start.row].substring(range.start.column,
return this.$lines[range.start.row].substring(range.start.column,
range.end.column);
}
else {
var lines = [];
lines.push(this.lines[range.start.row].substring(range.start.column));
lines.push(this.$lines[range.start.row].substring(range.start.column));
lines.push.apply(lines, this.getLines(range.start.row+1, range.end.row-1));
lines.push(this.lines[range.end.row].substring(0, range.end.column));
lines.push(this.$lines[range.end.row].substring(0, range.end.column));
return lines.join(this.$getNewLineCharacter());
}
};
@ -466,7 +466,7 @@ var Document = function(text, mode) {
* @param rows Array[Integer] sorted list of rows
*/
this.multiRowInsert = function(rows, column, text) {
var lines = this.lines;
var lines = this.$lines;
for (var i=rows.length-1; i>=0; i--) {
var row = rows[i];
@ -507,7 +507,7 @@ var Document = function(text, mode) {
var args = [row, 0];
args.push.apply(args, lines);
this.lines.splice.apply(this.lines, args);
this.$lines.splice.apply(this.$lines, args);
if (!fromUndo && this.$undoManager) {
var nl = this.$getNewLineCharacter();
@ -525,16 +525,16 @@ var Document = function(text, mode) {
return position;
this.modified = true;
if (this.lines.length <= 1) {
if (this.$lines.length <= 1) {
this.$detectNewLine(text);
}
var newLines = this.$split(text);
if (this.$isNewLine(text)) {
var line = this.lines[position.row] || "";
this.lines[position.row] = line.substring(0, position.column);
this.lines.splice(position.row + 1, 0, line.substring(position.column));
var line = this.$lines[position.row] || "";
this.$lines[position.row] = line.substring(0, position.column);
this.$lines.splice(position.row + 1, 0, line.substring(position.column));
var end = {
row : position.row + 1,
@ -542,8 +542,8 @@ var Document = function(text, mode) {
};
}
else if (newLines.length == 1) {
var line = this.lines[position.row] || "";
this.lines[position.row] = line.substring(0, position.column) + text
var line = this.$lines[position.row] || "";
this.$lines[position.row] = line.substring(0, position.column) + text
+ line.substring(position.column);
var end = {
@ -552,11 +552,11 @@ var Document = function(text, mode) {
};
}
else {
var line = this.lines[position.row] || "";
var line = this.$lines[position.row] || "";
var firstLine = line.substring(0, position.column) + newLines[0];
var lastLine = newLines[newLines.length - 1] + line.substring(position.column);
this.lines[position.row] = firstLine;
this.$lines[position.row] = firstLine;
this.$insertLines(position.row + 1, [lastLine], true);
if (newLines.length > 2) {
@ -603,7 +603,7 @@ var Document = function(text, mode) {
var height = range.end.row - rows[0];
for (var i=rows.length-1; i>=0; i--) {
var row = rows[i];
if (row >= this.lines.length)
if (row >= this.$lines.length)
continue;
var end = this.$remove(new Range(row, range.start.column, row+height, range.end.column), false);
@ -640,9 +640,9 @@ var Document = function(text, mode) {
+ this.getLine(lastRow).substring(range.end.column);
if (row != "")
this.lines.splice(firstRow, lastRow - firstRow + 1, row);
this.$lines.splice(firstRow, lastRow - firstRow + 1, row);
else
this.lines.splice(firstRow, lastRow - firstRow + 1, "");
this.$lines.splice(firstRow, lastRow - firstRow + 1, "");
return range.start;
};
@ -743,8 +743,8 @@ var Document = function(text, mode) {
this.moveLinesUp = function(firstRow, lastRow) {
if (firstRow <= 0) return 0;
var removed = this.lines.slice(firstRow, lastRow + 1);
this.$remove(new Range(firstRow-1, this.lines[firstRow-1].length, lastRow, this.lines[lastRow].length));
var removed = this.$lines.slice(firstRow, lastRow + 1);
this.$remove(new Range(firstRow-1, this.$lines[firstRow-1].length, lastRow, this.$lines[lastRow].length));
this.$insertLines(firstRow - 1, removed);
this.fireChangeEvent(firstRow - 1, lastRow);
@ -752,9 +752,9 @@ var Document = function(text, mode) {
};
this.moveLinesDown = function(firstRow, lastRow) {
if (lastRow >= this.lines.length-1) return 0;
if (lastRow >= this.$lines.length-1) return 0;
var removed = this.lines.slice(firstRow, lastRow + 1);
var removed = this.$lines.slice(firstRow, lastRow + 1);
this.$remove(new Range(firstRow, 0, lastRow + 1, 0));
this.$insertLines(firstRow+1, removed);
@ -776,7 +776,7 @@ var Document = function(text, mode) {
};
this.$clipRowToDocument = function(row) {
return Math.max(0, Math.min(row, this.lines.length-1));
return Math.max(0, Math.min(row, this.$lines.length-1));
};
this.documentToScreenColumn = function(row, docColumn) {