do not modify dom from computeLayerConfig
This commit is contained in:
parent
9a2ee70af8
commit
9b8e236483
1 changed files with 46 additions and 44 deletions
|
|
@ -228,8 +228,6 @@ var VirtualRenderer = function(container, theme) {
|
||||||
if (this.scrollMargin.top && session.getScrollTop() <= 0)
|
if (this.scrollMargin.top && session.getScrollTop() <= 0)
|
||||||
session.setScrollTop(-this.scrollMargin.top);
|
session.setScrollTop(-this.scrollMargin.top);
|
||||||
|
|
||||||
this.scroller.className = "ace_scroller";
|
|
||||||
|
|
||||||
this.$cursorLayer.setSession(session);
|
this.$cursorLayer.setSession(session);
|
||||||
this.$markerBack.setSession(session);
|
this.$markerBack.setSession(session);
|
||||||
this.$markerFront.setSession(session);
|
this.$markerFront.setSession(session);
|
||||||
|
|
@ -359,6 +357,7 @@ var VirtualRenderer = function(container, theme) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$updateCachedSize = function(force, gutterWidth, width, height) {
|
this.$updateCachedSize = function(force, gutterWidth, width, height) {
|
||||||
|
height -= (this.$extraHeight || 0);
|
||||||
var changes = 0;
|
var changes = 0;
|
||||||
var size = this.$size;
|
var size = this.$size;
|
||||||
var oldSize = {
|
var oldSize = {
|
||||||
|
|
@ -407,8 +406,7 @@ var VirtualRenderer = function(container, theme) {
|
||||||
changes = changes | this.CHANGE_FULL;
|
changes = changes | this.CHANGE_FULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size.$dirty)
|
size.$dirty = !width || !height;
|
||||||
size.$dirty = !width && !height;
|
|
||||||
|
|
||||||
if (changes)
|
if (changes)
|
||||||
this._signal("resize", oldSize);
|
this._signal("resize", oldSize);
|
||||||
|
|
@ -750,12 +748,21 @@ var VirtualRenderer = function(container, theme) {
|
||||||
this.scrollBarH.setScrollLeft(this.scrollLeft + this.scrollMargin.left);
|
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) {
|
this.$renderChanges = function(changes, force) {
|
||||||
if (this.$changes) {
|
if (this.$changes) {
|
||||||
changes |= this.$changes;
|
changes |= this.$changes;
|
||||||
this.$changes = 0;
|
this.$changes = 0;
|
||||||
}
|
}
|
||||||
if ((!this.session || !this.container.offsetWidth) || (!changes && !force)) {
|
if ((!this.session || !this.container.offsetWidth || this.$frozen) || (!changes && !force)) {
|
||||||
this.$changes |= changes;
|
this.$changes |= changes;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -769,6 +776,7 @@ var VirtualRenderer = function(container, theme) {
|
||||||
// this.$logChanges(changes);
|
// this.$logChanges(changes);
|
||||||
|
|
||||||
this._signal("beforeRender");
|
this._signal("beforeRender");
|
||||||
|
var config = this.layerConfig;
|
||||||
// text, scrolling and resize changes can cause the view port size to change
|
// text, scrolling and resize changes can cause the view port size to change
|
||||||
if (changes & this.CHANGE_FULL ||
|
if (changes & this.CHANGE_FULL ||
|
||||||
changes & this.CHANGE_SIZE ||
|
changes & this.CHANGE_SIZE ||
|
||||||
|
|
@ -776,27 +784,33 @@ var VirtualRenderer = function(container, theme) {
|
||||||
changes & this.CHANGE_LINES ||
|
changes & this.CHANGE_LINES ||
|
||||||
changes & this.CHANGE_SCROLL ||
|
changes & this.CHANGE_SCROLL ||
|
||||||
changes & this.CHANGE_H_SCROLL
|
changes & this.CHANGE_H_SCROLL
|
||||||
)
|
) {
|
||||||
changes |= this.$computeLayerConfig();
|
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
|
// horizontal scrolling
|
||||||
if (changes & this.CHANGE_H_SCROLL) {
|
if (changes & this.CHANGE_H_SCROLL) {
|
||||||
this.$updateScrollBarH();
|
|
||||||
this.content.style.marginLeft = -this.scrollLeft + "px";
|
this.content.style.marginLeft = -this.scrollLeft + "px";
|
||||||
this.scroller.className = this.scrollLeft <= 0 ? "ace_scroller" : "ace_scroller ace_scroll-left";
|
this.scroller.className = this.scrollLeft <= 0 ? "ace_scroller" : "ace_scroller ace_scroll-left";
|
||||||
}
|
}
|
||||||
|
|
||||||
// full
|
// full
|
||||||
if (changes & this.CHANGE_FULL) {
|
if (changes & this.CHANGE_FULL) {
|
||||||
// update scrollbar first to not lose scroll position when gutter calls resize
|
this.$textLayer.update(config);
|
||||||
this.$updateScrollBarV();
|
|
||||||
this.$updateScrollBarH();
|
|
||||||
this.$textLayer.update(this.layerConfig);
|
|
||||||
if (this.$showGutter)
|
if (this.$showGutter)
|
||||||
this.$gutterLayer.update(this.layerConfig);
|
this.$gutterLayer.update(config);
|
||||||
this.$markerBack.update(this.layerConfig);
|
this.$markerBack.update(config);
|
||||||
this.$markerFront.update(this.layerConfig);
|
this.$markerFront.update(config);
|
||||||
this.$cursorLayer.update(this.layerConfig);
|
this.$cursorLayer.update(config);
|
||||||
this.$moveTextAreaToCursor();
|
this.$moveTextAreaToCursor();
|
||||||
this.$highlightGutterLine && this.$updateGutterLineHighlight();
|
this.$highlightGutterLine && this.$updateGutterLineHighlight();
|
||||||
this._signal("afterRender");
|
this._signal("afterRender");
|
||||||
|
|
@ -805,17 +819,16 @@ var VirtualRenderer = function(container, theme) {
|
||||||
|
|
||||||
// scrolling
|
// scrolling
|
||||||
if (changes & this.CHANGE_SCROLL) {
|
if (changes & this.CHANGE_SCROLL) {
|
||||||
this.$updateScrollBarV();
|
|
||||||
if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES)
|
if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES)
|
||||||
this.$textLayer.update(this.layerConfig);
|
this.$textLayer.update(config);
|
||||||
else
|
else
|
||||||
this.$textLayer.scrollLines(this.layerConfig);
|
this.$textLayer.scrollLines(config);
|
||||||
|
|
||||||
if (this.$showGutter)
|
if (this.$showGutter)
|
||||||
this.$gutterLayer.update(this.layerConfig);
|
this.$gutterLayer.update(config);
|
||||||
this.$markerBack.update(this.layerConfig);
|
this.$markerBack.update(config);
|
||||||
this.$markerFront.update(this.layerConfig);
|
this.$markerFront.update(config);
|
||||||
this.$cursorLayer.update(this.layerConfig);
|
this.$cursorLayer.update(config);
|
||||||
this.$highlightGutterLine && this.$updateGutterLineHighlight();
|
this.$highlightGutterLine && this.$updateGutterLineHighlight();
|
||||||
this.$moveTextAreaToCursor();
|
this.$moveTextAreaToCursor();
|
||||||
this._signal("afterRender");
|
this._signal("afterRender");
|
||||||
|
|
@ -823,49 +836,44 @@ var VirtualRenderer = function(container, theme) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changes & this.CHANGE_TEXT) {
|
if (changes & this.CHANGE_TEXT) {
|
||||||
this.$textLayer.update(this.layerConfig);
|
this.$textLayer.update(config);
|
||||||
if (this.$showGutter)
|
if (this.$showGutter)
|
||||||
this.$gutterLayer.update(this.layerConfig);
|
this.$gutterLayer.update(config);
|
||||||
}
|
}
|
||||||
else if (changes & this.CHANGE_LINES) {
|
else if (changes & this.CHANGE_LINES) {
|
||||||
if (this.$updateLines() || (changes & this.CHANGE_GUTTER) && this.$showGutter)
|
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) {
|
else if (changes & this.CHANGE_TEXT || changes & this.CHANGE_GUTTER) {
|
||||||
if (this.$showGutter)
|
if (this.$showGutter)
|
||||||
this.$gutterLayer.update(this.layerConfig);
|
this.$gutterLayer.update(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changes & this.CHANGE_CURSOR) {
|
if (changes & this.CHANGE_CURSOR) {
|
||||||
this.$cursorLayer.update(this.layerConfig);
|
this.$cursorLayer.update(config);
|
||||||
this.$moveTextAreaToCursor();
|
this.$moveTextAreaToCursor();
|
||||||
this.$highlightGutterLine && this.$updateGutterLineHighlight();
|
this.$highlightGutterLine && this.$updateGutterLineHighlight();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_FRONT)) {
|
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)) {
|
if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_BACK)) {
|
||||||
this.$markerBack.update(this.layerConfig);
|
this.$markerBack.update(config);
|
||||||
}
|
|
||||||
|
|
||||||
if (changes & this.CHANGE_SIZE || changes & this.CHANGE_LINES) {
|
|
||||||
this.$updateScrollBarV();
|
|
||||||
this.$updateScrollBarH();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._signal("afterRender");
|
this._signal("afterRender");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
this.$autosize = function(height, width) {
|
this.$autosize = function() {
|
||||||
var height = this.session.getScreenLength() * this.lineHeight;
|
var height = this.session.getScreenLength() * this.lineHeight;
|
||||||
var maxHeight = this.$maxLines * this.lineHeight;
|
var maxHeight = this.$maxLines * this.lineHeight;
|
||||||
var desiredHeight = Math.max(
|
var desiredHeight = Math.max(
|
||||||
(this.$minLines||1) * this.lineHeight,
|
(this.$minLines||1) * this.lineHeight,
|
||||||
Math.min(maxHeight, height)
|
Math.min(maxHeight, height)
|
||||||
);
|
) + this.scrollMargin.v + (this.$extraHeight || 0);
|
||||||
var vScroll = height > maxHeight;
|
var vScroll = height > maxHeight;
|
||||||
|
|
||||||
if (desiredHeight != this.desiredHeight ||
|
if (desiredHeight != this.desiredHeight ||
|
||||||
|
|
@ -890,7 +898,7 @@ var VirtualRenderer = function(container, theme) {
|
||||||
var session = this.session;
|
var session = this.session;
|
||||||
|
|
||||||
var hideScrollbars = this.$size.height <= 2 * this.lineHeight;
|
var hideScrollbars = this.$size.height <= 2 * this.lineHeight;
|
||||||
var screenLines = this.session.getScreenLength()
|
var screenLines = this.session.getScreenLength();
|
||||||
var maxHeight = screenLines * this.lineHeight;
|
var maxHeight = screenLines * this.lineHeight;
|
||||||
|
|
||||||
var offset = this.scrollTop % this.lineHeight;
|
var offset = this.scrollTop % this.lineHeight;
|
||||||
|
|
@ -981,12 +989,6 @@ var VirtualRenderer = function(container, theme) {
|
||||||
// For debugging.
|
// For debugging.
|
||||||
// console.log(JSON.stringify(this.layerConfig));
|
// 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;
|
return changes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue