Use a rowCache that does auto chaing every 1000 lines
This commit is contained in:
parent
a3496dfad1
commit
af13eb544b
3 changed files with 60 additions and 34 deletions
|
|
@ -85,7 +85,7 @@ exports.launch = function(env) {
|
||||||
|
|
||||||
// Make the lorem ipsum text a little bit longer.
|
// Make the lorem ipsum text a little bit longer.
|
||||||
var loreIpsum = document.getElementById("plaintext").innerHTML;
|
var loreIpsum = document.getElementById("plaintext").innerHTML;
|
||||||
for (var i = 0; i < 11; i++) {
|
for (var i = 0; i < 5; i++) {
|
||||||
loreIpsum += loreIpsum;
|
loreIpsum += loreIpsum;
|
||||||
}
|
}
|
||||||
docs.plain = new EditSession(loreIpsum);
|
docs.plain = new EditSession(loreIpsum);
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,8 @@ var EditSession = function(text, mode) {
|
||||||
this.$frontMarkers = {};
|
this.$frontMarkers = {};
|
||||||
this.$backMarkers = {};
|
this.$backMarkers = {};
|
||||||
this.$markerId = 1;
|
this.$markerId = 1;
|
||||||
|
this.$rowCache = [];
|
||||||
|
this.$rowCacheSize = 1000;
|
||||||
this.$wrapData = [];
|
this.$wrapData = [];
|
||||||
this.$foldData = [];
|
this.$foldData = [];
|
||||||
this.$foldData.toString = function() {
|
this.$foldData.toString = function() {
|
||||||
|
|
@ -103,6 +105,20 @@ var EditSession = function(text, mode) {
|
||||||
this.$docChangeCounter ++;
|
this.$docChangeCounter ++;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.$resetRowCache = function(row) {
|
||||||
|
var rowCache = this.$rowCache;
|
||||||
|
if (row == 0) {
|
||||||
|
rowCache = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < rowCache.length; i++) {
|
||||||
|
if (rowCache[i].docRow >= row) {
|
||||||
|
rowCache.splice(i, rowCache.length);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.onChangeEnd = function() {
|
this.onChangeEnd = function() {
|
||||||
this.$docChangeCounter --;
|
this.$docChangeCounter --;
|
||||||
if (this.$docChangeCounter == 0
|
if (this.$docChangeCounter == 0
|
||||||
|
|
@ -128,22 +144,14 @@ var EditSession = function(text, mode) {
|
||||||
|
|
||||||
this.onChangeFold = function(e) {
|
this.onChangeFold = function(e) {
|
||||||
var fold = e.data;
|
var fold = e.data;
|
||||||
if (this.$cacheRowData
|
this.$resetRowCache(fold.start.row);
|
||||||
&& fold.start.row < this.$cacheRowData.docRow)
|
|
||||||
{
|
|
||||||
this.$cacheRowData = null;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onChange = function(e) {
|
this.onChange = function(e) {
|
||||||
var delta = e.data;
|
var delta = e.data;
|
||||||
this.$modified = true;
|
this.$modified = true;
|
||||||
|
|
||||||
if (this.$cacheRowData
|
this.$resetRowCache(delta.range.start.row);
|
||||||
&& delta.range.start.row < this.$cacheRowData.docRow)
|
|
||||||
{
|
|
||||||
this.$cacheRowData = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var removedFolds = this.$updateInternalDataOnChange(e);
|
var removedFolds = this.$updateInternalDataOnChange(e);
|
||||||
if (!this.$fromUndo && this.$undoManager && !delta.ignore) {
|
if (!this.$fromUndo && this.$undoManager && !delta.ignore) {
|
||||||
|
|
@ -162,10 +170,10 @@ var EditSession = function(text, mode) {
|
||||||
|
|
||||||
this.setValue = function(text) {
|
this.setValue = function(text) {
|
||||||
this.doc.setValue(text);
|
this.doc.setValue(text);
|
||||||
|
this.$resetRowCache(0);
|
||||||
this.$deltas = [];
|
this.$deltas = [];
|
||||||
this.$deltasDoc = [];
|
this.$deltasDoc = [];
|
||||||
this.$deltasFold = [];
|
this.$deltasFold = [];
|
||||||
this.$cacheRowData = null;
|
|
||||||
this.getUndoManager().reset();
|
this.getUndoManager().reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -188,6 +196,7 @@ var EditSession = function(text, mode) {
|
||||||
|
|
||||||
this.setUndoManager = function(undoManager) {
|
this.setUndoManager = function(undoManager) {
|
||||||
this.$undoManager = undoManager;
|
this.$undoManager = undoManager;
|
||||||
|
this.$resetRowCache(0);
|
||||||
this.$deltas = [];
|
this.$deltas = [];
|
||||||
this.$deltasDoc = [];
|
this.$deltasDoc = [];
|
||||||
this.$deltasFold = [];
|
this.$deltasFold = [];
|
||||||
|
|
@ -882,6 +891,7 @@ var EditSession = function(text, mode) {
|
||||||
if (useWrapMode != this.$useWrapMode) {
|
if (useWrapMode != this.$useWrapMode) {
|
||||||
this.$useWrapMode = useWrapMode;
|
this.$useWrapMode = useWrapMode;
|
||||||
this.$modified = true;
|
this.$modified = true;
|
||||||
|
this.$resetRowCache(0);
|
||||||
|
|
||||||
// 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) {
|
||||||
|
|
@ -924,6 +934,7 @@ var EditSession = function(text, mode) {
|
||||||
this.$modified = true;
|
this.$modified = true;
|
||||||
if (this.$useWrapMode) {
|
if (this.$useWrapMode) {
|
||||||
this.$updateWrapData(0, this.getLength() - 1);
|
this.$updateWrapData(0, this.getLength() - 1);
|
||||||
|
this.$resetRowCache(0)
|
||||||
this._dispatchEvent("changeWrapLimit");
|
this._dispatchEvent("changeWrapLimit");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -1373,17 +1384,6 @@ var EditSession = function(text, mode) {
|
||||||
return this.screenToDocumentPosition(screenRow, screenColumn).column;
|
return this.screenToDocumentPosition(screenRow, screenColumn).column;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setCacheRow = function(docRow) {
|
|
||||||
// Don't update the cache if the docRow stayed the same.
|
|
||||||
if (this.$cacheRowData && this.$cacheRowData.docRow == docRow) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.$cacheRowData = {
|
|
||||||
docRow: docRow,
|
|
||||||
screenRow: this.documentToScreenRow(docRow, 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.screenToDocumentPosition = function(screenRow, screenColumn) {
|
this.screenToDocumentPosition = function(screenRow, screenColumn) {
|
||||||
var line;
|
var line;
|
||||||
var docRow = 0;
|
var docRow = 0;
|
||||||
|
|
@ -1396,13 +1396,26 @@ var EditSession = function(text, mode) {
|
||||||
var splits = null;
|
var splits = null;
|
||||||
var split = 0;
|
var split = 0;
|
||||||
|
|
||||||
var cacheRowData = this.$cacheRowData;
|
var rowCache = this.$rowCache;
|
||||||
if (cacheRowData && cacheRowData.screenRow < screenRow) {
|
var doCache = !rowCache.length;
|
||||||
row = cacheRowData.screenRow ;
|
for (var i = 0; i < rowCache.length; i++) {
|
||||||
docRow = cacheRowData.docRow;
|
if (rowCache[i].screenRow < screenRow) {
|
||||||
|
row = rowCache[i].screenRow;
|
||||||
|
docRow = rowCache[i].docRow;
|
||||||
|
doCache = i == rowCache.length - 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
var docRowCacheLast = docRow;
|
||||||
|
|
||||||
while (row <= screenRow) {
|
while (row <= screenRow) {
|
||||||
|
if (doCache
|
||||||
|
&& docRow - docRowCacheLast > this.$rowCacheSize) {
|
||||||
|
rowCache.push({
|
||||||
|
docRow: docRow,
|
||||||
|
screenRow: row
|
||||||
|
});
|
||||||
|
docRowCacheLast = docRow;
|
||||||
|
}
|
||||||
rowLength = this.getRowLength(docRow);
|
rowLength = this.getRowLength(docRow);
|
||||||
if (row + rowLength - 1 >= screenRow) {
|
if (row + rowLength - 1 >= screenRow) {
|
||||||
break;
|
break;
|
||||||
|
|
@ -1486,13 +1499,28 @@ var EditSession = function(text, mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var rowEnd, row = 0;
|
var rowEnd, row = 0;
|
||||||
var cacheRowData = this.$cacheRowData;
|
var rowCache = this.$rowCache;
|
||||||
if (cacheRowData && cacheRowData.docRow < docRow) {
|
//
|
||||||
row = cacheRowData.docRow ;
|
var doCache = !rowCache.length;
|
||||||
screenRow = cacheRowData.screenRow// + this.getRowLength(row);;
|
for (var i = 0; i < rowCache.length; i++) {
|
||||||
|
if (rowCache[i].docRow < docRow) {
|
||||||
|
screenRow = rowCache[i].screenRow;
|
||||||
|
row = rowCache[i].docRow;
|
||||||
|
doCache = i == rowCache.length - 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
var docRowCacheLast = row;
|
||||||
|
|
||||||
while (row < docRow) {
|
while (row < docRow) {
|
||||||
|
if (doCache
|
||||||
|
&& row - docRowCacheLast > this.$rowCacheSize) {
|
||||||
|
rowCache.push({
|
||||||
|
docRow: row,
|
||||||
|
screenRow: screenRow
|
||||||
|
});
|
||||||
|
docRowCacheLast = row;
|
||||||
|
}
|
||||||
|
|
||||||
rowEnd = this.getRowFoldEnd(row);
|
rowEnd = this.getRowFoldEnd(row);
|
||||||
if (rowEnd >= docRow) {
|
if (rowEnd >= docRow) {
|
||||||
break;
|
break;
|
||||||
|
|
@ -1541,10 +1569,10 @@ var EditSession = function(text, mode) {
|
||||||
|
|
||||||
this.getScreenLength = function() {
|
this.getScreenLength = function() {
|
||||||
var length = this.getLength();
|
var length = this.getLength();
|
||||||
|
var screenRows = 0;
|
||||||
if (!this.$useWrapMode) {
|
if (!this.$useWrapMode) {
|
||||||
screenRows = length;
|
screenRows = length;
|
||||||
} else {
|
} else {
|
||||||
var screenRows = 0;
|
|
||||||
for (var row = 0; row < this.$wrapData.length; row++) {
|
for (var row = 0; row < this.$wrapData.length; row++) {
|
||||||
screenRows += this.$wrapData[row].length + 1;
|
screenRows += this.$wrapData[row].length + 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -479,8 +479,6 @@ var VirtualRenderer = function(container, theme) {
|
||||||
var lineHeight = { lineHeight: this.lineHeight };
|
var lineHeight = { lineHeight: this.lineHeight };
|
||||||
firstRow = session.screenToDocumentRow(firstRow, 0);
|
firstRow = session.screenToDocumentRow(firstRow, 0);
|
||||||
|
|
||||||
session.setCacheRow(firstRow);
|
|
||||||
|
|
||||||
// Check if firstRow is inside of a foldLine. If true, then use the first
|
// Check if firstRow is inside of a foldLine. If true, then use the first
|
||||||
// row of the foldLine.
|
// row of the foldLine.
|
||||||
var foldLine = session.getFoldLine(firstRow);
|
var foldLine = session.getFoldLine(firstRow);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue