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

@ -131,7 +131,7 @@ var Text = function(parentEl) {
container.appendChild(measureNode);
}
}
// Size and width can be null if the editor is not visible or
// detached from the document
if (!this.element.offsetWidth)
@ -153,7 +153,7 @@ var Text = function(parentEl) {
return null;
return size;
}
}
: function() {
if (!this.$measureNode) {
var measureNode = this.$measureNode = dom.createElement("div");
@ -178,7 +178,7 @@ var Text = function(parentEl) {
container.appendChild(measureNode);
}
var rect = this.$measureNode.getBoundingClientRect();
var size = {
@ -382,7 +382,7 @@ var Text = function(parentEl) {
"lparen": true
};
this.$renderToken = function(stringBuilder, screenColumn, token, value) {
this.$renderToken = function(stringBuilder, screenColumn, token, value) {
var self = this;
var replaceReg = /\t|&|<|( +)|([\u0000-\u0019\u00a0\u1680\u180E\u2000-\u200b\u2028\u2029\u202F\u205F\u3000\uFEFF])|[\u1100-\u115F\u11A3-\u11A7\u11FA-\u11FF\u2329-\u232A\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFB\u3000-\u303E\u3041-\u3096\u3099-\u30FF\u3105-\u312D\u3131-\u318E\u3190-\u31BA\u31C0-\u31E3\u31F0-\u321E\u3220-\u3247\u3250-\u32FE\u3300-\u4DBF\u4E00-\uA48C\uA490-\uA4C6\uA960-\uA97C\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFAFF\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE66\uFE68-\uFE6B\uFF01-\uFF60\uFFE0-\uFFE6]/g;
var replaceFunc = function(c, a, b, tabIdx, idx4) {
@ -447,7 +447,7 @@ var Text = function(parentEl) {
"'>"
);
}
for (var i = 0; i < tokens.length; i++) {
var token = tokens[i];
var value = token.value;
@ -461,12 +461,12 @@ var Text = function(parentEl) {
else {
while (chars + value.length >= splitChars) {
screenColumn = self.$renderToken(
stringBuilder, screenColumn,
stringBuilder, screenColumn,
token, value.substring(0, splitChars - chars)
);
value = value.substring(splitChars - chars);
chars = splitChars;
if (!onlyContents) {
stringBuilder.push("</div>",
"<div class='ace_line' style='height:",
@ -510,9 +510,9 @@ var Text = function(parentEl) {
};
this.$renderFoldLine = function(stringBuilder, row, tokens, onlyContents) {
var session = this.session,
foldLine = session.getFoldLine(row),
renderTokens = [];
var session = this.session;
var foldLine = session.getFoldLine(row);
var renderTokens = [];
function addTokens(tokens, from, to) {
var idx = 0, col = 0;
@ -520,16 +520,14 @@ var Text = function(parentEl) {
col += tokens[idx].value.length;
idx++;
if (idx == tokens.length) {
if (idx == tokens.length)
return;
}
}
if (col != from) {
var value = tokens[idx].value.substring(from - col);
// 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);
}
renderTokens.push({
type: tokens[idx].type,
@ -540,15 +538,15 @@ var Text = function(parentEl) {
idx += 1;
}
while (col < to) {
while (col < to && idx < tokens.length) {
var value = tokens[idx].value;
if (value.length + col > to) {
value = value.substring(0, to - col);
}
renderTokens.push({
type: tokens[idx].type,
value: value
});
renderTokens.push({
type: tokens[idx].type,
value: value.substring(0, to - col)
});
} else
renderTokens.push(tokens[idx]);
col += value.length;
idx += 1;
}
@ -556,27 +554,27 @@ var Text = function(parentEl) {
foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
if (placeholder) {
renderTokens.push({
renderTokens.push({
type: "fold",
value: placeholder
});
} else {
if (isNewRow)
tokens = this.session.getTokens(row);
tokens = session.getTokens(row);
if (tokens.length)
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!
var splits = this.session.$useWrapMode?this.session.$wrapData[row]:null;
// splits for foldline are stored at its' first row
var splits = this.session.$useWrapMode ? this.session.$wrapData[row] : null;
this.$renderLineCore(stringBuilder, row, renderTokens, splits, onlyContents);
};
this.$useLineGroups = function() {
// For the updateLines function to work correctly, it's important that the
// child nodes of this.element correspond on a 1-to-1 basis to rows in the
// child nodes of this.element correspond on a 1-to-1 basis to rows in the
// document (as distinct from lines on the screen). For sessions that are
// wrapped, this means we need to add a layer to the node hierarchy (tagged
// with the class name ace_line_group).