Skip to content

Commit

Permalink
Get rid of refreshDisplay update algorithm
Browse files Browse the repository at this point in the history
It seems patchDisplay is always faster

Closes #233
  • Loading branch information
marijnh committed Nov 8, 2011
1 parent 9560ca6 commit 6b5773b
Showing 1 changed file with 1 addition and 26 deletions.
27 changes: 1 addition & 26 deletions lib/codemirror.js
Expand Up @@ -880,13 +880,7 @@ var CodeMirror = (function() {
if (!updates.length) return;
var th = textHeight(), gutterDisplay = gutter.style.display;
lineDiv.style.display = gutter.style.display = "none";
// If more than 30% of the screen needs update, just do a full
// redraw (which is quicker than patching)
if (changedLines > (visible.to - visible.from) * .3)
refreshDisplay(from = Math.max(visible.from - 10, 0), to = Math.min(visible.to + 7, doc.size));
// Otherwise, only update the stuff that needs updating.
else
patchDisplay(updates);
patchDisplay(updates);
lineDiv.style.display = "";

// Position the mover div to align with the lines it's supposed
Expand Down Expand Up @@ -930,25 +924,6 @@ var CodeMirror = (function() {
updateCursor();
}

function refreshDisplay(from, to) {
var start = {line: from, ch: 0}, inSel = posLess(sel.from, start) && !posLess(sel.to, start);
var i = from, html = [];
doc.iter(from, to, function(line) {
var ch1 = null, ch2 = null;
if (inSel) {
ch1 = 0;
if (sel.to.line == i) {inSel = false; ch2 = sel.to.ch;}
}
else if (sel.from.line == i) {
if (sel.to.line == i) {ch1 = sel.from.ch; ch2 = sel.to.ch;}
else {inSel = true; ch1 = sel.from.ch;}
}
if (line.hidden) html.push("<pre></pre>");
else html.push(line.getHTML(ch1, ch2, true));
++i;
});
lineDiv.innerHTML = html.join("");
}
function patchDisplay(updates) {
// Slightly different algorithm for IE (badInnerHTML), since
// there .innerHTML on PRE nodes is dumb, and discards
Expand Down

0 comments on commit 6b5773b

Please sign in to comment.