folds with wrong range shouldn't break renderer

This commit is contained in:
nightwing 2012-06-10 22:10:35 +04:00
commit 7f8892f9a5

View file

@ -510,9 +510,9 @@ var Text = function(parentEl) {
}; };
this.$renderFoldLine = function(stringBuilder, row, tokens, onlyContents) { this.$renderFoldLine = function(stringBuilder, row, tokens, onlyContents) {
var session = this.session, var session = this.session;
foldLine = session.getFoldLine(row), var foldLine = session.getFoldLine(row);
renderTokens = []; var renderTokens = [];
function addTokens(tokens, from, to) { function addTokens(tokens, from, to) {
var idx = 0, col = 0; var idx = 0, col = 0;
@ -520,16 +520,14 @@ var Text = function(parentEl) {
col += tokens[idx].value.length; col += tokens[idx].value.length;
idx++; idx++;
if (idx == tokens.length) { if (idx == tokens.length)
return; return;
}
} }
if (col != from) { if (col != from) {
var value = tokens[idx].value.substring(from - col); var value = tokens[idx].value.substring(from - col);
// Check if the token value is longer then the from...to spacing. // Check if the token value is longer then the from...to spacing.
if (value.length > (to - from)) { if (value.length > (to - from))
value = value.substring(0, to - from); value = value.substring(0, to - from);
}
renderTokens.push({ renderTokens.push({
type: tokens[idx].type, type: tokens[idx].type,
@ -540,15 +538,15 @@ var Text = function(parentEl) {
idx += 1; idx += 1;
} }
while (col < to) { while (col < to && idx < tokens.length) {
var value = tokens[idx].value; var value = tokens[idx].value;
if (value.length + col > to) { if (value.length + col > to) {
value = value.substring(0, to - col); renderTokens.push({
} type: tokens[idx].type,
renderTokens.push({ value: value.substring(0, to - col)
type: tokens[idx].type, });
value: value } else
}); renderTokens.push(tokens[idx]);
col += value.length; col += value.length;
idx += 1; idx += 1;
} }
@ -556,21 +554,21 @@ var Text = function(parentEl) {
foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) { foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
if (placeholder) { if (placeholder) {
renderTokens.push({ renderTokens.push({
type: "fold", type: "fold",
value: placeholder value: placeholder
}); });
} else { } else {
if (isNewRow) if (isNewRow)
tokens = this.session.getTokens(row); tokens = session.getTokens(row);
if (tokens.length) if (tokens.length)
addTokens(tokens, lastColumn, column); addTokens(tokens, lastColumn, column);
} }
}.bind(this), foldLine.end.row, this.session.getLine(foldLine.end.row).length); }, foldLine.end.row, this.session.getLine(foldLine.end.row).length);
// TODO: Build a fake splits array! // splits for foldline are stored at its' first row
var splits = this.session.$useWrapMode?this.session.$wrapData[row]:null; var splits = this.session.$useWrapMode ? this.session.$wrapData[row] : null;
this.$renderLineCore(stringBuilder, row, renderTokens, splits, onlyContents); this.$renderLineCore(stringBuilder, row, renderTokens, splits, onlyContents);
}; };