faster documentToScreenPosition

This commit is contained in:
nightwing 2011-05-21 18:35:59 +05:00 • committed by Fabian Jakobs
commit 4787744645
3 changed files with 22 additions and 21 deletions

View file

@ -1503,7 +1503,6 @@ var EditSession = function(text, mode) {
} }
var wrapData; var wrapData;
// Special case in wrapMode if the doc is at the end of the document. // Special case in wrapMode if the doc is at the end of the document.
if (this.$useWrapMode) { if (this.$useWrapMode) {
wrapData = this.$wrapData; wrapData = this.$wrapData;
@ -1517,13 +1516,10 @@ var EditSession = function(text, mode) {
} }
} }
var screenRow = 0, var screenRow = 0;
screenColumn = 0, var screenColumn = 0;
foldStartRow = null, var foldStartRow = null;
fold = null, var fold = null;
folds,
comp,
foldLine = null;
// Clamp the docRow position in case it's inside of a folded block. // Clamp the docRow position in case it's inside of a folded block.
fold = this.getFoldAt(docRow, docColumn, 1); fold = this.getFoldAt(docRow, docColumn, 1);
@ -1545,7 +1541,19 @@ var EditSession = function(text, mode) {
} }
var docRowCacheLast = row; var docRowCacheLast = row;
var foldLine = this.getNextFold(row);
var foldStart = foldLine ?foldLine.start.row :Infinity;
while (row < docRow) { while (row < docRow) {
if (row >= foldStart) {
rowEnd = foldLine.end.row + 1;
if (rowEnd > docRow)
break;
foldLine = this.getNextFold(rowEnd);
foldStart = foldLine ?foldLine.start.row :Infinity;
} else {
rowEnd = row + 1;
}
if (doCache if (doCache
&& row - docRowCacheLast > this.$rowCacheSize) { && row - docRowCacheLast > this.$rowCacheSize) {
rowCache.push({ rowCache.push({
@ -1555,26 +1563,20 @@ var EditSession = function(text, mode) {
docRowCacheLast = row; docRowCacheLast = row;
} }
rowEnd = this.getRowFoldEnd(row);
if (rowEnd >= docRow) {
break;
}
screenRow += this.getRowLength(row); screenRow += this.getRowLength(row);
row = rowEnd + 1; row = rowEnd;
} }
// Calculate the text line that is displayed in docRow on the screen. // Calculate the text line that is displayed in docRow on the screen.
var textLine = ""; var textLine = "";
foldLine = this.getFoldLine(docRow);
// Check if the final row we want to reach is inside of a fold. // Check if the final row we want to reach is inside of a fold.
if (!foldLine) { if (foldLine && row >= foldStart) {
textLine = this.getLine(docRow).substring(0, docColumn);
foldStartRow = docRow;
} else {
textLine = this.getFoldDisplayLine(foldLine, docRow, docColumn); textLine = this.getFoldDisplayLine(foldLine, docRow, docColumn);
foldStartRow = foldLine.start.row; foldStartRow = foldLine.start.row;
} else {
textLine = this.getLine(docRow).substring(0, docColumn);
foldStartRow = docRow;
} }
// Clamp textLine if in wrapMode. // Clamp textLine if in wrapMode.
if (this.$useWrapMode) { if (this.$useWrapMode) {
var wrapRow = wrapData[foldStartRow]; var wrapRow = wrapData[foldStartRow];

View file

@ -489,7 +489,6 @@ function Folding() {
}; };
this.getRowFoldEnd = function(docRow, startFoldRow) { this.getRowFoldEnd = function(docRow, startFoldRow) {
//console.trace()
var foldLine = this.getFoldLine(docRow, startFoldRow); var foldLine = this.getFoldLine(docRow, startFoldRow);
return (foldLine return (foldLine
? foldLine.end.row ? foldLine.end.row

View file

@ -513,7 +513,7 @@ var Text = function(parentEl) {
}.bind(this), foldLine.end.row, this.session.getLine(foldLine.end.row).length); }.bind(this), foldLine.end.row, this.session.getLine(foldLine.end.row).length);
// TODO: Build a fake splits array! // TODO: Build a fake splits array!
var splits = this.session.$wrapData[row]; var splits = this.session.$useWrapMode?this.session.$wrapData[row]:null;
this.$renderLineCore(stringBuilder, row, renderTokens, splits); this.$renderLineCore(stringBuilder, row, renderTokens, splits);
}; };