fix bug when same folded row is shown twice while scrolling

and optimize usage of getRowFoldEnd
This commit is contained in:
nightwing 2011-05-10 20:54:44 +05:00
commit 3cd9162103
3 changed files with 97 additions and 19 deletions

View file

@ -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;
});
});