fix rendering of wrapped foldlines

This commit is contained in:
nightwing 2011-11-17 20:55:54 +04:00
commit a931d239d7
2 changed files with 34 additions and 29 deletions

View file

@ -1061,9 +1061,11 @@ var EditSession = function(text, mode) {
var row = firstRow; var row = firstRow;
lastRow = Math.min(lastRow, lines.length - 1); lastRow = Math.min(lastRow, lines.length - 1);
while (row <= lastRow) { while (row <= lastRow) {
foldLine = this.getFoldLine(row); foldLine = this.getFoldLine(row, foldLine);
if (!foldLine) { if (!foldLine) {
tokens = this.$getDisplayTokens(lang.stringTrimRight(lines[row])); tokens = this.$getDisplayTokens(lang.stringTrimRight(lines[row]));
wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
row ++;
} else { } else {
tokens = []; tokens = [];
foldLine.walk( foldLine.walk(
@ -1087,16 +1089,13 @@ var EditSession = function(text, mode) {
lines[foldLine.end.row].length + 1 lines[foldLine.end.row].length + 1
); );
// Remove spaces/tabs from the back of the token array. // Remove spaces/tabs from the back of the token array.
while (tokens.length != 0 while (tokens.length != 0 && tokens[tokens.length - 1] >= SPACE)
&& tokens[tokens.length - 1] >= SPACE)
{
tokens.pop(); 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); line = this.getFoldDisplayLine(foldLine);
else { docRow = foldLine.start.row;
} else {
line = this.getLine(docRow); line = this.getLine(docRow);
foldLine = null; foldLine = null;
} }
var splits = [];
if (this.$useWrapMode) { if (this.$useWrapMode) {
splits = this.$wrapData[docRow]; var splits = this.$wrapData[docRow];
if (splits) { if (splits) {
column = splits[screenRow - row] column = splits[screenRow - row];
if(screenRow > row && splits.length) { if(screenRow > row && splits.length) {
docColumn = splits[screenRow - row - 1] || splits[splits.length - 1]; docColumn = splits[screenRow - row - 1] || splits[splits.length - 1];
line = line.substring(docColumn); line = line.substring(docColumn);
@ -1436,7 +1435,7 @@ var EditSession = function(text, mode) {
docColumn += this.$getStringScreenWidth(line, screenColumn)[1]; docColumn += this.$getStringScreenWidth(line, screenColumn)[1];
// clip row at the end of the document // clip row at the end of the document
if (row + splits.length < screenRow) if (docRow > maxRow)
docColumn = Number.MAX_VALUE; docColumn = Number.MAX_VALUE;
// Need to do some clamping action here. // Need to do some clamping action here.
@ -1577,24 +1576,29 @@ var EditSession = function(text, mode) {
this.getScreenLength = function() { this.getScreenLength = function() {
var screenRows = 0; var screenRows = 0;
var lastFoldLine = null; var fold = null;
var foldLine = null;
if (!this.$useWrapMode) { if (!this.$useWrapMode) {
screenRows = this.getLength(); screenRows = this.getLength();
// Remove the folded lines again. // Remove the folded lines again.
var foldData = this.$foldData; var foldData = this.$foldData;
for (var i = 0; i < foldData.length; i++) { for (var i = 0; i < foldData.length; i++) {
foldLine = foldData[i]; fold = foldData[i];
screenRows -= foldLine.end.row - foldLine.start.row; screenRows -= fold.end.row - fold.start.row;
} }
} else { } else {
for (var row = 0; row < this.$wrapData.length; row++) { var lastRow = this.$wrapData.length;
if (foldLine = this.getFoldLine(row, lastFoldLine)) { var row = 0, i = 0;
row = foldLine.end.row; var fold = this.$foldData[i++];
screenRows += 1; var foldStart = fold ? fold.start.row :Infinity;
} else {
screenRows += this.$wrapData[row].length + 1; 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;
} }
} }
} }

View file

@ -201,6 +201,7 @@ var Text = function(parentEl) {
var foldLine = this.session.getFoldLine(row); var foldLine = this.session.getFoldLine(row);
if (foldLine) { if (foldLine) {
if (foldLine.containsRow(first)) { if (foldLine.containsRow(first)) {
first = foldLine.start.row;
break; break;
} else { } else {
row = foldLine.end.row; row = foldLine.end.row;
@ -264,12 +265,12 @@ var Text = function(parentEl) {
foldStart = fold ?fold.start.row :Infinity; foldStart = fold ?fold.start.row :Infinity;
while (true) { while (true) {
if(row > foldStart) { if (row > foldStart) {
row = fold.end.row+1; row = fold.end.row+1;
fold = this.session.getNextFoldLine(row, fold); fold = this.session.getNextFoldLine(row, fold);
foldStart = fold ?fold.start.row :Infinity; foldStart = fold ?fold.start.row :Infinity;
} }
if(row > lastRow) if (row > lastRow)
break; break;
var container = dom.createElement("div"); var container = dom.createElement("div");
@ -311,12 +312,12 @@ var Text = function(parentEl) {
foldStart = fold ?fold.start.row :Infinity; foldStart = fold ?fold.start.row :Infinity;
while (true) { while (true) {
if(row > foldStart) { if (row > foldStart) {
row = fold.end.row+1; row = fold.end.row+1;
fold = this.session.getNextFoldLine(row, fold); fold = this.session.getNextFoldLine(row, fold);
foldStart = fold ?fold.start.row :Infinity; foldStart = fold ?fold.start.row :Infinity;
} }
if(row > lastRow) if (row > lastRow)
break; break;
if (this.$useLineGroups()) if (this.$useLineGroups())