do not modify dom from computeLayerConfig

This commit is contained in:
nightwing 2013-11-24 16:19:59 +04:00
commit 9b8e236483

View file

@ -228,8 +228,6 @@ var VirtualRenderer = function(container, theme) {
if (this.scrollMargin.top && session.getScrollTop() <= 0)
session.setScrollTop(-this.scrollMargin.top);
this.scroller.className = "ace_scroller";
this.$cursorLayer.setSession(session);
this.$markerBack.setSession(session);
this.$markerFront.setSession(session);
@ -359,6 +357,7 @@ var VirtualRenderer = function(container, theme) {
};
this.$updateCachedSize = function(force, gutterWidth, width, height) {
height -= (this.$extraHeight || 0);
var changes = 0;
var size = this.$size;
var oldSize = {
@ -407,8 +406,7 @@ var VirtualRenderer = function(container, theme) {
changes = changes | this.CHANGE_FULL;
}
if (size.$dirty)
size.$dirty = !width && !height;
size.$dirty = !width || !height;
if (changes)
this._signal("resize", oldSize);
@ -749,13 +747,22 @@ var VirtualRenderer = function(container, theme) {
this.scrollBarH.setInnerWidth(this.layerConfig.width + 2 * this.$padding + this.scrollMargin.h);
this.scrollBarH.setScrollLeft(this.scrollLeft + this.scrollMargin.left);
};
this.$frozen = false;
this.freeze = function() {
this.$frozen = true;
};
this.unfreeze = function() {
this.$frozen = false;
};
this.$renderChanges = function(changes, force) {
if (this.$changes) {
changes |= this.$changes;
this.$changes = 0;
}
if ((!this.session || !this.container.offsetWidth) || (!changes && !force)) {
if ((!this.session || !this.container.offsetWidth || this.$frozen) || (!changes && !force)) {
this.$changes |= changes;
return;
}
@ -769,6 +776,7 @@ var VirtualRenderer = function(container, theme) {
// this.$logChanges(changes);
this._signal("beforeRender");
var config = this.layerConfig;
// text, scrolling and resize changes can cause the view port size to change
if (changes & this.CHANGE_FULL ||
changes & this.CHANGE_SIZE ||
@ -776,27 +784,33 @@ var VirtualRenderer = function(container, theme) {
changes & this.CHANGE_LINES ||
changes & this.CHANGE_SCROLL ||
changes & this.CHANGE_H_SCROLL
)
) {
changes |= this.$computeLayerConfig();
config = this.layerConfig;
// update scrollbar first to not lose scroll position when gutter calls resize
this.$updateScrollBarV();
if (changes & this.CHANGE_H_SCROLL)
this.$updateScrollBarH();
this.$gutterLayer.element.style.marginTop = (-config.offset) + "px";
this.content.style.marginTop = (-config.offset) + "px";
this.content.style.width = config.width + 2 * this.$padding + "px";
this.content.style.height = config.minHeight + "px";
}
// horizontal scrolling
if (changes & this.CHANGE_H_SCROLL) {
this.$updateScrollBarH();
this.content.style.marginLeft = -this.scrollLeft + "px";
this.scroller.className = this.scrollLeft <= 0 ? "ace_scroller" : "ace_scroller ace_scroll-left";
}
// full
if (changes & this.CHANGE_FULL) {
// update scrollbar first to not lose scroll position when gutter calls resize
this.$updateScrollBarV();
this.$updateScrollBarH();
this.$textLayer.update(this.layerConfig);
this.$textLayer.update(config);
if (this.$showGutter)
this.$gutterLayer.update(this.layerConfig);
this.$markerBack.update(this.layerConfig);
this.$markerFront.update(this.layerConfig);
this.$cursorLayer.update(this.layerConfig);
this.$gutterLayer.update(config);
this.$markerBack.update(config);
this.$markerFront.update(config);
this.$cursorLayer.update(config);
this.$moveTextAreaToCursor();
this.$highlightGutterLine && this.$updateGutterLineHighlight();
this._signal("afterRender");
@ -805,17 +819,16 @@ var VirtualRenderer = function(container, theme) {
// scrolling
if (changes & this.CHANGE_SCROLL) {
this.$updateScrollBarV();
if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES)
this.$textLayer.update(this.layerConfig);
this.$textLayer.update(config);
else
this.$textLayer.scrollLines(this.layerConfig);
this.$textLayer.scrollLines(config);
if (this.$showGutter)
this.$gutterLayer.update(this.layerConfig);
this.$markerBack.update(this.layerConfig);
this.$markerFront.update(this.layerConfig);
this.$cursorLayer.update(this.layerConfig);
this.$gutterLayer.update(config);
this.$markerBack.update(config);
this.$markerFront.update(config);
this.$cursorLayer.update(config);
this.$highlightGutterLine && this.$updateGutterLineHighlight();
this.$moveTextAreaToCursor();
this._signal("afterRender");
@ -823,49 +836,44 @@ var VirtualRenderer = function(container, theme) {
}
if (changes & this.CHANGE_TEXT) {
this.$textLayer.update(this.layerConfig);
this.$textLayer.update(config);
if (this.$showGutter)
this.$gutterLayer.update(this.layerConfig);
this.$gutterLayer.update(config);
}
else if (changes & this.CHANGE_LINES) {
if (this.$updateLines() || (changes & this.CHANGE_GUTTER) && this.$showGutter)
this.$gutterLayer.update(this.layerConfig);
this.$gutterLayer.update(config);
}
else if (changes & this.CHANGE_TEXT || changes & this.CHANGE_GUTTER) {
if (this.$showGutter)
this.$gutterLayer.update(this.layerConfig);
this.$gutterLayer.update(config);
}
if (changes & this.CHANGE_CURSOR) {
this.$cursorLayer.update(this.layerConfig);
this.$cursorLayer.update(config);
this.$moveTextAreaToCursor();
this.$highlightGutterLine && this.$updateGutterLineHighlight();
}
if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_FRONT)) {
this.$markerFront.update(this.layerConfig);
this.$markerFront.update(config);
}
if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_BACK)) {
this.$markerBack.update(this.layerConfig);
}
if (changes & this.CHANGE_SIZE || changes & this.CHANGE_LINES) {
this.$updateScrollBarV();
this.$updateScrollBarH();
this.$markerBack.update(config);
}
this._signal("afterRender");
};
this.$autosize = function(height, width) {
this.$autosize = function() {
var height = this.session.getScreenLength() * this.lineHeight;
var maxHeight = this.$maxLines * this.lineHeight;
var desiredHeight = Math.max(
(this.$minLines||1) * this.lineHeight,
Math.min(maxHeight, height)
);
) + this.scrollMargin.v + (this.$extraHeight || 0);
var vScroll = height > maxHeight;
if (desiredHeight != this.desiredHeight ||
@ -890,7 +898,7 @@ var VirtualRenderer = function(container, theme) {
var session = this.session;
var hideScrollbars = this.$size.height <= 2 * this.lineHeight;
var screenLines = this.session.getScreenLength()
var screenLines = this.session.getScreenLength();
var maxHeight = screenLines * this.lineHeight;
var offset = this.scrollTop % this.lineHeight;
@ -981,12 +989,6 @@ var VirtualRenderer = function(container, theme) {
// For debugging.
// console.log(JSON.stringify(this.layerConfig));
this.$gutterLayer.element.style.marginTop = (-offset) + "px";
this.content.style.marginTop = (-offset) + "px";
this.content.style.width = longestLine + 2 * this.$padding + "px";
this.content.style.height = minHeight + "px";
return changes;
return changes;
};