there was one unnecessary div per line

This commit is contained in:
Fabian Jakobs 2011-07-28 14:01:23 +02:00
commit 011964cced

View file

@ -193,8 +193,8 @@ var Text = function(parentEl) {
var first = Math.max(firstRow, config.firstRow); var first = Math.max(firstRow, config.firstRow);
var last = Math.min(lastRow, config.lastRow); var last = Math.min(lastRow, config.lastRow);
var lineElements = this.element.childNodes, var lineElements = this.element.childNodes;
lineElementsIdx = 0; var lineElementsIdx = 0;
for (var row = config.firstRow; row < first; row++) { for (var row = config.firstRow; row < first; row++) {
var foldLine = this.session.getFoldLine(row); var foldLine = this.session.getFoldLine(row);
@ -215,7 +215,7 @@ var Text = function(parentEl) {
var html = []; var html = [];
var tokens = this.session.getTokens(i, i); var tokens = this.session.getTokens(i, i);
this.$renderLine(html, i, tokens[0].tokens); this.$renderLine(html, i, tokens[0].tokens, true);
lineElement = dom.setInnerHtml(lineElement, html.join("")); lineElement = dom.setInnerHtml(lineElement, html.join(""));
i = this.session.getRowFoldEnd(i); i = this.session.getRowFoldEnd(i);
@ -271,9 +271,7 @@ var Text = function(parentEl) {
if(row > lastRow) if(row > lastRow)
break; break;
var lineEl = dom.createElement("div"); var container = dom.createElement("div");
lineEl.className = "ace_line";
var html = []; var html = [];
// Get the tokens per line as there might be some lines in between // Get the tokens per line as there might be some lines in between
@ -282,11 +280,13 @@ var Text = function(parentEl) {
// this call once for that big block of unfolded lines. // this call once for that big block of unfolded lines.
var tokens = this.session.getTokens(row, row); var tokens = this.session.getTokens(row, row);
if (tokens.length == 1) if (tokens.length == 1)
this.$renderLine(html, row, tokens[0].tokens); this.$renderLine(html, row, tokens[0].tokens, false);
// don't use setInnerHtml since we are working with an empty DIV // don't use setInnerHtml since we are working with an empty DIV
lineEl.innerHTML = html.join(""); container.innerHTML = html.join("");
fragment.appendChild(lineEl); var lines = container.childNodes
while(lines.length)
fragment.appendChild(lines[0]);
row++; row++;
} }
@ -313,15 +313,13 @@ var Text = function(parentEl) {
if(row > lastRow) if(row > lastRow)
break; break;
html.push("<div class='ace_line'>");
// Get the tokens per line as there might be some lines in between // Get the tokens per line as there might be some lines in between
// beeing folded. // beeing folded.
// OPTIMIZE: If there is a long block of unfolded lines, just make // OPTIMIZE: If there is a long block of unfolded lines, just make
// this call once for that big block of unfolded lines. // this call once for that big block of unfolded lines.
var tokens = this.session.getTokens(row, row); var tokens = this.session.getTokens(row, row);
if (tokens.length == 1) if (tokens.length == 1)
this.$renderLine(html, row, tokens[0].tokens); this.$renderLine(html, row, tokens[0].tokens, false);
html.push("</div>");
row++; row++;
} }
@ -378,7 +376,7 @@ var Text = function(parentEl) {
return screenColumn + value.length; return screenColumn + value.length;
}; };
this.$renderLineCore = function(stringBuilder, lastRow, tokens, splits) { this.$renderLineCore = function(stringBuilder, lastRow, tokens, splits, onlyContents) {
var chars = 0; var chars = 0;
var split = 0; var split = 0;
var splitChars; var splitChars;
@ -388,7 +386,8 @@ var Text = function(parentEl) {
function addToken(token, value) { function addToken(token, value) {
screenColumn = self.$renderToken( screenColumn = self.$renderToken(
stringBuilder, screenColumn, token, value); stringBuilder, screenColumn, token, value
);
} }
if (!splits || splits.length == 0) { if (!splits || splits.length == 0) {
@ -397,9 +396,13 @@ var Text = function(parentEl) {
splitChars = splits[0]; splitChars = splits[0];
} }
stringBuilder.push("<div style='height:", if (!onlyContents) {
this.config.lineHeight, "px", stringBuilder.push("<div class='ace_line' style='height:",
"'>"); this.config.lineHeight, "px",
"'>"
);
}
for (var i = 0; i < tokens.length; i++) { for (var i = 0; i < tokens.length; i++) {
var token = tokens[i]; var token = tokens[i];
var value = token.value; var value = token.value;
@ -412,10 +415,14 @@ var Text = function(parentEl) {
addToken(token, value.substring(0, splitChars - chars)); addToken(token, value.substring(0, splitChars - chars));
value = value.substring(splitChars - chars); value = value.substring(splitChars - chars);
chars = splitChars; chars = splitChars;
stringBuilder.push("</div>",
"<div style='height:", if (!onlyContents) {
this.config.lineHeight, "px", stringBuilder.push("</div>",
"'>"); "<div class='ace_line' style='height:",
this.config.lineHeight, "px",
"'>"
);
}
split ++; split ++;
screenColumn = 0; screenColumn = 0;
@ -438,18 +445,18 @@ var Text = function(parentEl) {
stringBuilder.push("</div>"); stringBuilder.push("</div>");
}; };
this.$renderLine = function(stringBuilder, row, tokens) { this.$renderLine = function(stringBuilder, row, tokens, onlyContents) {
// Check if the line to render is folded or not. If not, things are // Check if the line to render is folded or not. If not, things are
// simple, otherwise, we need to fake some things... // simple, otherwise, we need to fake some things...
if (!this.session.isRowFolded(row)) { if (!this.session.isRowFolded(row)) {
var splits = this.session.getRowSplitData(row); var splits = this.session.getRowSplitData(row);
this.$renderLineCore(stringBuilder, row, tokens, splits); this.$renderLineCore(stringBuilder, row, tokens, splits, onlyContents);
} else { } else {
this.$renderFoldLine(stringBuilder, row, tokens); this.$renderFoldLine(stringBuilder, row, tokens, onlyContents);
} }
}; };
this.$renderFoldLine = function(stringBuilder, row, tokens) { this.$renderFoldLine = function(stringBuilder, row, tokens, onlyContents) {
var session = this.session, var session = this.session,
foldLine = session.getFoldLine(row), foldLine = session.getFoldLine(row),
renderTokens = []; renderTokens = [];
@ -512,7 +519,7 @@ var Text = function(parentEl) {
// TODO: Build a fake splits array! // TODO: Build a fake splits array!
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); this.$renderLineCore(stringBuilder, row, renderTokens, splits, onlyContents);
}; };
this.destroy = function() { this.destroy = function() {