From 4787744645840965171ec89777f2f1a615005391 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sat, 21 May 2011 18:35:59 +0500 Subject: [PATCH] faster documentToScreenPosition --- lib/ace/edit_session.js | 40 +++++++++++++++++---------------- lib/ace/edit_session/folding.js | 1 - lib/ace/layer/text.js | 2 +- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index 606121e9..4313e934 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -1503,7 +1503,6 @@ var EditSession = function(text, mode) { } var wrapData; - // Special case in wrapMode if the doc is at the end of the document. if (this.$useWrapMode) { wrapData = this.$wrapData; @@ -1517,13 +1516,10 @@ var EditSession = function(text, mode) { } } - var screenRow = 0, - screenColumn = 0, - foldStartRow = null, - fold = null, - folds, - comp, - foldLine = null; + var screenRow = 0; + var screenColumn = 0; + var foldStartRow = null; + var fold = null; // Clamp the docRow position in case it's inside of a folded block. fold = this.getFoldAt(docRow, docColumn, 1); @@ -1545,7 +1541,19 @@ var EditSession = function(text, mode) { } var docRowCacheLast = row; + var foldLine = this.getNextFold(row); + var foldStart = foldLine ?foldLine.start.row :Infinity; + 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 && row - docRowCacheLast > this.$rowCacheSize) { rowCache.push({ @@ -1555,26 +1563,20 @@ var EditSession = function(text, mode) { docRowCacheLast = row; } - rowEnd = this.getRowFoldEnd(row); - if (rowEnd >= docRow) { - break; - } screenRow += this.getRowLength(row); - row = rowEnd + 1; + row = rowEnd; } // Calculate the text line that is displayed in docRow on the screen. var textLine = ""; - foldLine = this.getFoldLine(docRow); // Check if the final row we want to reach is inside of a fold. - if (!foldLine) { - textLine = this.getLine(docRow).substring(0, docColumn); - foldStartRow = docRow; - } else { + if (foldLine && row >= foldStart) { textLine = this.getFoldDisplayLine(foldLine, docRow, docColumn); foldStartRow = foldLine.start.row; + } else { + textLine = this.getLine(docRow).substring(0, docColumn); + foldStartRow = docRow; } - // Clamp textLine if in wrapMode. if (this.$useWrapMode) { var wrapRow = wrapData[foldStartRow]; diff --git a/lib/ace/edit_session/folding.js b/lib/ace/edit_session/folding.js index 904e0fb5..9a19575c 100644 --- a/lib/ace/edit_session/folding.js +++ b/lib/ace/edit_session/folding.js @@ -489,7 +489,6 @@ function Folding() { }; this.getRowFoldEnd = function(docRow, startFoldRow) { - //console.trace() var foldLine = this.getFoldLine(docRow, startFoldRow); return (foldLine ? foldLine.end.row diff --git a/lib/ace/layer/text.js b/lib/ace/layer/text.js index 88a4e1bf..bd186433 100644 --- a/lib/ace/layer/text.js +++ b/lib/ace/layer/text.js @@ -513,7 +513,7 @@ var Text = function(parentEl) { }.bind(this), foldLine.end.row, this.session.getLine(foldLine.end.row).length); // 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); };