the document's lines array is no longer public
This commit is contained in:
parent
ecf7ef04c8
commit
ed9b0d4f0a
5 changed files with 45 additions and 44 deletions
|
|
@ -42,7 +42,7 @@ var EventEmitter = require("pilot/event_emitter").EventEmitter;
|
|||
|
||||
var BackgroundTokenizer = function(tokenizer, editor) {
|
||||
this.running = false;
|
||||
this.textLines = [];
|
||||
this.doc = [];
|
||||
this.lines = [];
|
||||
this.currentLine = 0;
|
||||
this.tokenizer = tokenizer;
|
||||
|
|
@ -54,12 +54,13 @@ var BackgroundTokenizer = function(tokenizer, editor) {
|
|||
|
||||
var workerStart = new Date();
|
||||
var startLine = self.currentLine;
|
||||
var textLines = self.textLines;
|
||||
var doc = self.doc;
|
||||
|
||||
var processedLines = 0;
|
||||
var lastVisibleRow = editor.getLastVisibleRow();
|
||||
|
||||
while (self.currentLine < textLines.length) {
|
||||
var len = doc.getLength();
|
||||
while (self.currentLine < len) {
|
||||
self.lines[self.currentLine] = self.$tokenizeRows(self.currentLine, self.currentLine)[0];
|
||||
self.currentLine++;
|
||||
|
||||
|
|
@ -76,7 +77,7 @@ var BackgroundTokenizer = function(tokenizer, editor) {
|
|||
|
||||
self.running = false;
|
||||
|
||||
self.fireUpdateEvent(startLine, textLines.length - 1);
|
||||
self.fireUpdateEvent(startLine, len - 1);
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -91,8 +92,8 @@ var BackgroundTokenizer = function(tokenizer, editor) {
|
|||
this.start(0);
|
||||
};
|
||||
|
||||
this.setLines = function(textLines) {
|
||||
this.textLines = textLines;
|
||||
this.setDocument = function(doc) {
|
||||
this.doc = doc;
|
||||
this.lines = [];
|
||||
|
||||
this.stop();
|
||||
|
|
@ -108,7 +109,7 @@ var BackgroundTokenizer = function(tokenizer, editor) {
|
|||
|
||||
this.start = function(startRow) {
|
||||
this.currentLine = Math.min(startRow || 0, this.currentLine,
|
||||
this.textLines.length);
|
||||
this.doc.getLength());
|
||||
|
||||
// remove all cached items below this line
|
||||
this.lines.splice(this.currentLine, this.lines.length);
|
||||
|
|
@ -143,9 +144,10 @@ var BackgroundTokenizer = function(tokenizer, editor) {
|
|||
doCache = true;
|
||||
}
|
||||
|
||||
var lines = this.doc.getLines(firstRow, lastRow);
|
||||
for (var row=firstRow; row<=lastRow; row++) {
|
||||
if (!this.lines[row]) {
|
||||
var tokens = this.tokenizer.getLineTokens(this.textLines[row] || "", state);
|
||||
var tokens = this.tokenizer.getLineTokens(lines[row-firstRow] || "", state);
|
||||
var state = tokens.state;
|
||||
rows.push(tokens);
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ var Editor =function(renderer, doc) {
|
|||
this.selection.addEventListener("changeSelection", this.$onSelectionChange);
|
||||
|
||||
this.onDocumentModeChange();
|
||||
this.bgTokenizer.setLines(this.doc.lines);
|
||||
this.bgTokenizer.setDocument(doc);
|
||||
this.bgTokenizer.start(0);
|
||||
|
||||
this.onCursorChange();
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ MockRenderer.prototype.getMouseEventTarget = function() {
|
|||
};
|
||||
|
||||
MockRenderer.prototype.setDocument = function(doc) {
|
||||
this.lines = doc.lines;
|
||||
this.doc = doc;
|
||||
};
|
||||
|
||||
MockRenderer.prototype.setTokenizer = function() {
|
||||
|
|
@ -91,7 +91,7 @@ MockRenderer.prototype.scrollCursorIntoView = function() {
|
|||
};
|
||||
|
||||
MockRenderer.prototype.scrollToRow = function(row) {
|
||||
var row = Math.min(this.lines.length - this.visibleRowCount, Math.max(0,
|
||||
var row = Math.min(this.doc.getLength() - this.visibleRowCount, Math.max(0,
|
||||
row));
|
||||
this.layerConfig.firstVisibleRow = row;
|
||||
this.layerConfig.lastVisibleRow = row + this.visibleRowCount;
|
||||
|
|
|
|||
|
|
@ -134,7 +134,6 @@ var VirtualRenderer = function(container, theme) {
|
|||
oop.implement(this, EventEmitter);
|
||||
|
||||
this.setDocument = function(doc) {
|
||||
this.lines = doc.lines;
|
||||
this.doc = doc;
|
||||
this.$cursorLayer.setDocument(doc);
|
||||
this.$markerLayer.setDocument(doc);
|
||||
|
|
@ -396,7 +395,7 @@ var VirtualRenderer = function(container, theme) {
|
|||
|
||||
var lineCount = Math.ceil(minHeight / this.lineHeight);
|
||||
var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
|
||||
var lastRow = Math.max(0, Math.min(this.lines.length, firstRow + lineCount) - 1);
|
||||
var lastRow = Math.max(0, Math.min(this.doc.getLength(), firstRow + lineCount) - 1);
|
||||
|
||||
var layerConfig = this.layerConfig = {
|
||||
width : longestLine,
|
||||
|
|
@ -531,7 +530,7 @@ var VirtualRenderer = function(container, theme) {
|
|||
};
|
||||
|
||||
this.scrollToY = function(scrollTop) {
|
||||
var maxHeight = this.lines.length * this.lineHeight - this.$size.scrollerHeight;
|
||||
var maxHeight = this.doc.getLength() * this.lineHeight - this.$size.scrollerHeight;
|
||||
var scrollTop = Math.max(0, Math.min(maxHeight, scrollTop));
|
||||
|
||||
if (this.scrollTop !== scrollTop) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue