Skip to content

Commit

Permalink
Use operations for all display updates
Browse files Browse the repository at this point in the history
Stop passing 'true' as a changeset to updateDisplay, simplify a bunch
of things.
  • Loading branch information
marijnh committed Jan 21, 2013
1 parent f99237c commit dc2a6ef
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions lib/codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ window.CodeMirror = (function() {

function guttersChanged(cm) {
updateGutters(cm);
updateDisplay(cm, true);
regChange(cm);
}

function updateGutters(cm) {
Expand Down Expand Up @@ -421,18 +421,18 @@ window.CodeMirror = (function() {
// to render instead of the current scrollbar position.
var visible = visibleLines(display, doc, viewPort);
// Bail out if the visible area is already rendered and nothing changed.
if (changes !== true && changes.length == 0 &&
if (changes.length == 0 &&
visible.from > display.showingFrom && visible.to < display.showingTo)
return;

if (changes && maybeUpdateLineNumberWidth(cm))
changes = true;
if (maybeUpdateLineNumberWidth(cm))
changes = [{from: doc.first, to: doc.first + doc.size}];
var gutterW = display.sizer.style.marginLeft = display.gutters.offsetWidth + "px";
display.scrollbarH.style.left = cm.options.fixedGutter ? gutterW : "0";

// When merged lines are present, the line that needs to be
// redrawn might not be the one that was changed.
if (changes !== true && sawCollapsedSpans)
if (sawCollapsedSpans)
for (var i = 0; i < changes.length; ++i) {
var ch = changes[i], merged;
while (merged = collapsedSpanAtStart(getLine(doc, ch.from))) {
Expand All @@ -443,8 +443,8 @@ window.CodeMirror = (function() {
}

// Used to determine which lines need their line numbers updated
var positionsChangedFrom = changes === true ? doc.first : Infinity;
if (cm.options.lineNumbers && changes && changes !== true)
var positionsChangedFrom = Infinity;
if (cm.options.lineNumbers)
for (var i = 0; i < changes.length; ++i)
if (changes[i].diff) { positionsChangedFrom = changes[i].from; break; }

Expand All @@ -460,8 +460,7 @@ window.CodeMirror = (function() {

// Create a range of theoretically intact lines, and punch holes
// in that using the change info.
var intact = changes === true ? [] :
computeIntact([{from: display.showingFrom, to: display.showingTo}], changes);
var intact = computeIntact([{from: display.showingFrom, to: display.showingTo}], changes);

// Clip off the parts that won't be visible
var intactLines = 0;
Expand Down Expand Up @@ -1354,7 +1353,7 @@ window.CodeMirror = (function() {
// Might be a text scaling operation, clear size caches.
d.cachedCharWidth = d.cachedTextHeight = null;
clearCaches(cm);
if (d.wrapper.parentNode) updateDisplay(cm, true);
if (d.wrapper.parentNode) runInOp(cm, bind(regChange, cm));
else off(window, "resize", resizeHandler);
});

Expand Down Expand Up @@ -2690,15 +2689,11 @@ window.CodeMirror = (function() {

operation: function(f){return runInOp(this, f);},

refresh: function() {
refresh: operation(null, function() {
clearCaches(this);
var sTop = this.doc.scrollTop, sLeft = this.doc.scrollLeft;
if (this.display.scroller.scrollHeight > sTop)
this.display.scrollbarV.scrollTop = this.display.scroller.scrollTop = sTop;
if (this.display.scroller.scrollWidth > sLeft)
this.display.scrollbarH.scrollLeft = this.display.scroller.scrollLeft = sLeft;
updateDisplay(this, true);
},
this.curOp.updateScrollPos = {scrollTop: this.doc.scrollTop, scrollLeft: this.doc.scrollLeft};
regChange(this);
}),

swapDoc: operation(null, function(doc) {
var old = this.doc;
Expand Down Expand Up @@ -2746,7 +2741,7 @@ window.CodeMirror = (function() {
option("tabSize", 4, function(cm) {
loadMode(cm);
clearCaches(cm);
updateDisplay(cm, true);
regChange(cm);
}, true);
option("electricChars", true);
option("rtlMoveVisually", !windows);
Expand Down

0 comments on commit dc2a6ef

Please sign in to comment.