create wrap data lazily

This commit is contained in:
nightwing 2013-11-01 00:28:01 +04:00
commit f4d1dc7c13

View file

@ -1556,10 +1556,7 @@ var EditSession = function(text, mode) {
// If wrapMode is activaed, the wrapData array has to be initialized. // If wrapMode is activaed, the wrapData array has to be initialized.
if (useWrapMode) { if (useWrapMode) {
var len = this.getLength(); var len = this.getLength();
this.$wrapData = []; this.$wrapData = Array(len);
for (var i = 0; i < len; i++) {
this.$wrapData.push([]);
}
this.$updateWrapData(0, len - 1); this.$updateWrapData(0, len - 1);
} }
@ -1719,16 +1716,10 @@ var EditSession = function(text, mode) {
lastRow = firstRow; lastRow = firstRow;
} else { } else {
var args; var args = Array(len);
if (useWrapMode) { args.unshift(firstRow, 0);
args = [firstRow, 0]; var arr = useWrapMode ? this.$wrapData : this.$rowLengthCache
for (var i = 0; i < len; i++) args.push([]); arr.splice.apply(arr, args);
this.$wrapData.splice.apply(this.$wrapData, args);
} else {
args = Array(len);
args.unshift(firstRow, 0);
this.$rowLengthCache.splice.apply(this.$rowLengthCache, args);
}
// If some new line is added inside of a foldLine, then split // If some new line is added inside of a foldLine, then split
// the fold line up. // the fold line up.
@ -1833,8 +1824,7 @@ var EditSession = function(text, mode) {
lines[foldLine.end.row].length + 1 lines[foldLine.end.row].length + 1
); );
wrapData[foldLine.start.row] wrapData[foldLine.start.row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
= this.$computeWrapSplits(tokens, wrapLimit, tabSize);
row = foldLine.end.row + 1; row = foldLine.end.row + 1;
} }
} }
@ -2023,9 +2013,6 @@ var EditSession = function(text, mode) {
* The first position indicates the number of columns for `str` on screen.<br/> * The first position indicates the number of columns for `str` on screen.<br/>
* The second value contains the position of the document column that this function read until. * The second value contains the position of the document column that this function read until.
* *
*
*
*
**/ **/
this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) { this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) {
if (maxScreenColumn == 0) if (maxScreenColumn == 0)
@ -2326,14 +2313,16 @@ var EditSession = function(text, mode) {
// Clamp textLine if in wrapMode. // Clamp textLine if in wrapMode.
if (this.$useWrapMode) { if (this.$useWrapMode) {
var wrapRow = this.$wrapData[foldStartRow]; var wrapRow = this.$wrapData[foldStartRow];
var screenRowOffset = 0; if (wrapRow) {
while (textLine.length >= wrapRow[screenRowOffset]) { var screenRowOffset = 0;
screenRow ++; while (textLine.length >= wrapRow[screenRowOffset]) {
screenRowOffset++; screenRow ++;
screenRowOffset++;
}
textLine = textLine.substring(
wrapRow[screenRowOffset - 1] || 0, textLine.length
);
} }
textLine = textLine.substring(
wrapRow[screenRowOffset - 1] || 0, textLine.length
);
} }
return { return {
@ -2387,7 +2376,8 @@ var EditSession = function(text, mode) {
var foldStart = fold ? fold.start.row :Infinity; var foldStart = fold ? fold.start.row :Infinity;
while (row < lastRow) { while (row < lastRow) {
screenRows += this.$wrapData[row].length + 1; var splits = this.$wrapData[row];
screenRows += splits ? splits.length + 1 : 1;
row ++; row ++;
if (row > foldStart) { if (row > foldStart) {
row = fold.end.row+1; row = fold.end.row+1;