From 03a88d3fcf81047b9d813cdbe0b322b666bcd35b Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 15 May 2011 23:09:13 +0500 Subject: [PATCH] faster screenToDocumentPosition, and right clamping for wrapped mode --- lib/ace/edit_session.js | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index 2c4c4737..de1cd453 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -1389,12 +1389,10 @@ var EditSession = function(text, mode) { var docRow = 0; var docColumn = 0; var column; - var foldLine; var foldLineRowLength; var row = 0; var rowLength = 0; var splits = null; - var split = 0; var rowCache = this.$rowCache; var doCache = !rowCache.length; @@ -1406,6 +1404,11 @@ var EditSession = function(text, mode) { } } var docRowCacheLast = docRow; + // clamp row before clamping column, for selection on last line + var maxRow = this.getLength() - 1; + + var foldLine = this.getNextFold(docRow); + var foldStart = foldLine ?foldLine.start.row :Infinity; while (row <= screenRow) { if (doCache @@ -1417,28 +1420,32 @@ var EditSession = function(text, mode) { docRowCacheLast = docRow; } rowLength = this.getRowLength(docRow); - if (row + rowLength - 1 >= screenRow) { + if (row + rowLength - 1 >= screenRow || docRow >= maxRow) { break; } else { row += rowLength; - docRow = this.getRowFoldEnd(docRow) + 1; + docRow++; + if(docRow > foldStart) { + docRow = foldLine.end.row+1; + foldLine = this.getNextFold(docRow); + foldStart = foldLine ?foldLine.start.row :Infinity; + } } } - // clamp row before clamping column, for selection on last line - var maxRow = this.getLength()-1 - if(docRow > maxRow) - docRow = maxRow; - - foldLine = this.getFoldLine(docRow); - line = foldLine - ? this.getFoldDisplayLine(foldLine) - : this.getLine(docRow); + if (foldLine && foldLine.start.row <= docRow) + line = this.getFoldDisplayLine(foldLine); + else { + line = this.getLine(docRow); + foldLine = null; + } if (this.$useWrapMode) { - splits = this.$wrapData[docRow] || []; - docColumn = split = splits[screenRow - row - 1] || 0; - line = line.substring(split); + splits = this.$wrapData[docRow]; + if (splits && screenRow > row && splits.length) { + docColumn = splits[screenRow - row - 1] || splits[splits.length - 1]; + line = line.substring(docColumn); + } } docColumn += this.$getStringScreenWidth(line, screenColumn)[1];