add virtualRenderer.$updateSizeAsync

This commit is contained in:
nightwing 2013-11-05 20:51:56 +04:00
commit f1973e4233

View file

@ -134,7 +134,8 @@ var VirtualRenderer = function(container, theme) {
width: 0, width: 0,
height: 0, height: 0,
scrollerHeight: 0, scrollerHeight: 0,
scrollerWidth: 0 scrollerWidth: 0,
$dirty: true
}; };
this.layerConfig = { this.layerConfig = {
@ -223,6 +224,9 @@ var VirtualRenderer = function(container, theme) {
**/ **/
this.setSession = function(session) { this.setSession = function(session) {
this.session = session; this.session = session;
if (this.scrollMargin.top && session.getScrollTop() <= 0)
session.setScrollTop(-this.scrollMargin.top);
this.scroller.className = "ace_scroller"; this.scroller.className = "ace_scroller";
@ -232,7 +236,6 @@ var VirtualRenderer = function(container, theme) {
this.$gutterLayer.setSession(session); this.$gutterLayer.setSession(session);
this.$textLayer.setSession(session); this.$textLayer.setSession(session);
this.$loop.schedule(this.CHANGE_FULL); this.$loop.schedule(this.CHANGE_FULL);
}; };
/** /**
@ -300,6 +303,12 @@ var VirtualRenderer = function(container, theme) {
}; };
this.$changes = 0; this.$changes = 0;
this.$updateSizeAsync = function() {
if (this.$loop.pending)
this.$size.$dirty = true;
else
this.onResize();
};
/** /**
* [Triggers a resize of the editor.]{: #VirtualRenderer.onResize} * [Triggers a resize of the editor.]{: #VirtualRenderer.onResize}
* @param {Boolean} force If `true`, recomputes the size, even if the height and width haven't changed * @param {Boolean} force If `true`, recomputes the size, even if the height and width haven't changed
@ -325,7 +334,6 @@ var VirtualRenderer = function(container, theme) {
height = el.clientHeight || el.scrollHeight; height = el.clientHeight || el.scrollHeight;
if (!width) if (!width)
width = el.clientWidth || el.scrollWidth; width = el.clientWidth || el.scrollWidth;
var changes = this.$updateCachedSize(force, gutterWidth, width, height); var changes = this.$updateCachedSize(force, gutterWidth, width, height);
// console.log("resizing to", width, height, JSON.stringify(this.$size)) // console.log("resizing to", width, height, JSON.stringify(this.$size))
@ -342,7 +350,7 @@ var VirtualRenderer = function(container, theme) {
this.$gutterLayer.$padding = null; this.$gutterLayer.$padding = null;
if (force) if (force)
this.$renderChanges(changes, true); this.$renderChanges(changes | this.$changes, true);
else else
this.$loop.schedule(changes | this.$changes); this.$loop.schedule(changes | this.$changes);
@ -371,7 +379,7 @@ var VirtualRenderer = function(container, theme) {
this.scrollBarV.element.style.bottom = this.scrollBarH.getHeight() + "px"; this.scrollBarV.element.style.bottom = this.scrollBarH.getHeight() + "px";
if (this.session) { if (this.session) {
this.session.setScrollTop(this.getScrollTop()); //this.session.setScrollTop(this.getScrollTop());
changes = changes | this.CHANGE_SCROLL; changes = changes | this.CHANGE_SCROLL;
} }
} }
@ -399,6 +407,9 @@ var VirtualRenderer = function(container, theme) {
changes = changes | this.CHANGE_FULL; changes = changes | this.CHANGE_FULL;
} }
if (size.$dirty)
size.$dirty = !width && !height;
if (changes) if (changes)
this._signal("resize", oldSize); this._signal("resize", oldSize);
@ -410,9 +421,11 @@ var VirtualRenderer = function(container, theme) {
if (gutterWidth != this.gutterWidth) if (gutterWidth != this.gutterWidth)
this.$changes |= this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height); this.$changes |= this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height);
if (this.session.getUseWrapMode() && this.adjustWrapLimit()) if (this.session.getUseWrapMode() && this.adjustWrapLimit()) {
this.$loop.schedule(this.CHANGE_FULL); this.$loop.schedule(this.CHANGE_FULL);
else { } else if (this.$size.$dirty) {
this.$loop.schedule(this.CHANGE_FULL);
} else {
this.$computeLayerConfig(); this.$computeLayerConfig();
this.$loop.schedule(this.CHANGE_MARKER); this.$loop.schedule(this.CHANGE_MARKER);
} }
@ -692,6 +705,8 @@ var VirtualRenderer = function(container, theme) {
sm.left = left|0; sm.left = left|0;
sm.v = sm.top + sm.bottom; sm.v = sm.top + sm.bottom;
sm.h = sm.left + sm.right; sm.h = sm.left + sm.right;
if (sm.top && this.scrollTop <= 0 && this.session)
this.session.setScrollTop(sm.top);
this.updateFull(); this.updateFull();
}; };
@ -744,7 +759,7 @@ var VirtualRenderer = function(container, theme) {
this.$changes |= changes; this.$changes |= changes;
return; return;
} }
if (!this.$size.width) { if (this.$size.$dirty) {
this.$changes |= changes; this.$changes |= changes;
return this.onResize(true); return this.onResize(true);
} }
@ -972,6 +987,7 @@ var VirtualRenderer = function(container, theme) {
this.content.style.height = minHeight + "px"; this.content.style.height = minHeight + "px";
return changes; return changes;
return changes;
}; };
this.$updateLines = function() { this.$updateLines = function() {