From a931d239d762aa9c82dc42adbc2c18cea533a362 Mon Sep 17 00:00:00 2001 From: nightwing Date: Thu, 17 Nov 2011 20:55:54 +0400 Subject: [PATCH] fix rendering of wrapped foldlines --- lib/ace/edit_session.js | 54 ++++++++++++++++++++++------------------- lib/ace/layer/text.js | 9 ++++--- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index 7b7f9a7d..621a6211 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -1061,9 +1061,11 @@ var EditSession = function(text, mode) { var row = firstRow; lastRow = Math.min(lastRow, lines.length - 1); while (row <= lastRow) { - foldLine = this.getFoldLine(row); + foldLine = this.getFoldLine(row, foldLine); if (!foldLine) { tokens = this.$getDisplayTokens(lang.stringTrimRight(lines[row])); + wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize); + row ++; } else { tokens = []; foldLine.walk( @@ -1087,16 +1089,13 @@ var EditSession = function(text, mode) { lines[foldLine.end.row].length + 1 ); // Remove spaces/tabs from the back of the token array. - while (tokens.length != 0 - && tokens[tokens.length - 1] >= SPACE) - { + while (tokens.length != 0 && tokens[tokens.length - 1] >= SPACE) tokens.pop(); - } - } - wrapData[row] = - this.$computeWrapSplits(tokens, wrapLimit, tabSize); - row = this.getRowFoldEnd(row) + 1; + wrapData[foldLine.start.row] + = this.$computeWrapSplits(tokens, wrapLimit, tabSize); + row = foldLine.end.row + 1; + } } }; @@ -1414,18 +1413,18 @@ var EditSession = function(text, mode) { } } - if (foldLine && foldLine.start.row <= docRow) + if (foldLine && foldLine.start.row <= docRow) { line = this.getFoldDisplayLine(foldLine); - else { + docRow = foldLine.start.row; + } else { line = this.getLine(docRow); foldLine = null; } - var splits = []; if (this.$useWrapMode) { - splits = this.$wrapData[docRow]; + var splits = this.$wrapData[docRow]; if (splits) { - column = splits[screenRow - row] + column = splits[screenRow - row]; if(screenRow > row && splits.length) { docColumn = splits[screenRow - row - 1] || splits[splits.length - 1]; line = line.substring(docColumn); @@ -1436,7 +1435,7 @@ var EditSession = function(text, mode) { docColumn += this.$getStringScreenWidth(line, screenColumn)[1]; // clip row at the end of the document - if (row + splits.length < screenRow) + if (docRow > maxRow) docColumn = Number.MAX_VALUE; // Need to do some clamping action here. @@ -1577,24 +1576,29 @@ var EditSession = function(text, mode) { this.getScreenLength = function() { var screenRows = 0; - var lastFoldLine = null; - var foldLine = null; + var fold = null; if (!this.$useWrapMode) { screenRows = this.getLength(); // Remove the folded lines again. var foldData = this.$foldData; for (var i = 0; i < foldData.length; i++) { - foldLine = foldData[i]; - screenRows -= foldLine.end.row - foldLine.start.row; + fold = foldData[i]; + screenRows -= fold.end.row - fold.start.row; } } else { - for (var row = 0; row < this.$wrapData.length; row++) { - if (foldLine = this.getFoldLine(row, lastFoldLine)) { - row = foldLine.end.row; - screenRows += 1; - } else { - screenRows += this.$wrapData[row].length + 1; + var lastRow = this.$wrapData.length; + var row = 0, i = 0; + var fold = this.$foldData[i++]; + var foldStart = fold ? fold.start.row :Infinity; + + while (row < lastRow) { + screenRows += this.$wrapData[row].length + 1; + row ++; + if (row > foldStart) { + row = fold.end.row+1; + fold = this.$foldData[i++]; + foldStart = fold ?fold.start.row :Infinity; } } } diff --git a/lib/ace/layer/text.js b/lib/ace/layer/text.js index 5fccd803..98670b02 100644 --- a/lib/ace/layer/text.js +++ b/lib/ace/layer/text.js @@ -201,6 +201,7 @@ var Text = function(parentEl) { var foldLine = this.session.getFoldLine(row); if (foldLine) { if (foldLine.containsRow(first)) { + first = foldLine.start.row; break; } else { row = foldLine.end.row; @@ -264,12 +265,12 @@ var Text = function(parentEl) { foldStart = fold ?fold.start.row :Infinity; while (true) { - if(row > foldStart) { + if (row > foldStart) { row = fold.end.row+1; fold = this.session.getNextFoldLine(row, fold); foldStart = fold ?fold.start.row :Infinity; } - if(row > lastRow) + if (row > lastRow) break; var container = dom.createElement("div"); @@ -311,12 +312,12 @@ var Text = function(parentEl) { foldStart = fold ?fold.start.row :Infinity; while (true) { - if(row > foldStart) { + if (row > foldStart) { row = fold.end.row+1; fold = this.session.getNextFoldLine(row, fold); foldStart = fold ?fold.start.row :Infinity; } - if(row > lastRow) + if (row > lastRow) break; if (this.$useLineGroups())