diff --git a/lib/ace/edit_session/folding.js b/lib/ace/edit_session/folding.js index 0e3fb889..3a2e6121 100644 --- a/lib/ace/edit_session/folding.js +++ b/lib/ace/edit_session/folding.js @@ -191,7 +191,11 @@ function Folding() { this.getFoldLine = function(docRow, startFoldLine) { var foldData = this.$foldData; - var i = Math.max(foldData.indexOf(startFoldLine), 0); + var i = 0; + if(startFoldLine) + i = foldData.indexOf(startFoldLine); + if(i == -1) + i = 0; for (i; i < foldData.length; i++) { var foldLine = foldData[i]; if (foldLine.start.row <= docRow && foldLine.end.row >= docRow) { @@ -203,6 +207,47 @@ function Folding() { return null; } + // returns the fold which starts after or contains docRow + this.getNextFold = function(docRow, startFoldLine) { + var foldData = this.$foldData, ans; + var i = 0; + if(startFoldLine) + i = foldData.indexOf(startFoldLine); + if(i == -1) + i = 0; + for (i; i < foldData.length; i++) { + var foldLine = foldData[i]; + if (foldLine.end.row >= docRow) { + return foldLine; + } + } + return null; + } + + this.getFoldedRowCount = function(first, last) { + var foldData = this.$foldData, rowCount = last-first+1; + for (var i = 0; i < foldData.length; i++) { + var foldLine = foldData[i], + end = foldLine.end.row, + start = foldLine.start.row; + if(end >= last) { + if(start < last) { + if(start >= first) + rowCount -= last-start; + else + rowCount = 0;//in one fold + } + break; + } else if(end >= first){ + if (start >= first) //fold inside range + rowCount -= end-start; + else + rowCount -= end-first+1; + } + } + return rowCount; + } + this.$addFoldLine = function(foldLine) { this.$foldData.push(foldLine); this.$foldData.sort(function(a, b) { @@ -428,6 +473,7 @@ function Folding() { }; this.getRowFoldEnd = function(docRow, startFoldRow) { + //console.trace() var foldLine = this.getFoldLine(docRow, startFoldRow); return (foldLine ? foldLine.end.row @@ -484,4 +530,4 @@ function Folding() { exports.Folding = Folding; -}); +}); \ No newline at end of file diff --git a/lib/ace/layer/gutter.js b/lib/ace/layer/gutter.js index 84a36ca2..344018ec 100644 --- a/lib/ace/layer/gutter.js +++ b/lib/ace/layer/gutter.js @@ -99,12 +99,22 @@ var Gutter = function(parentEl) { this.update = function(config) { this.$config = config; + var emptyAnno = {className: "", text: []}; var html = []; - for ( var i = config.firstRow; i <= config.lastRow; i++) { - var annotation = this.$annotations[i] || { - className: "", - text: [] - }; + var i = config.firstRow, lastRow = config.lastRow + fold = this.session.getNextFold(i), + foldStart = fold ?fold.start.row :Infinity; + + while (true) { + if(i > foldStart) { + i = fold.end.row+1; + fold = this.session.getNextFold(i); + foldStart = fold ?fold.start.row :Infinity; + } + if(i > lastRow) + break; + + var annotation = this.$annotations[i] || emptyAnno; html.push("