From 7f8a47939c746d4bb91eed9e020a9924713ace39 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 14 Jul 2013 07:47:17 +0400 Subject: [PATCH] renderer changes from newclient --- lib/ace/mouse/default_gutter_handler.js | 3 +- lib/ace/scrollbar.js | 21 ++-- lib/ace/virtual_renderer.js | 127 +++++++++++++++--------- 3 files changed, 94 insertions(+), 57 deletions(-) diff --git a/lib/ace/mouse/default_gutter_handler.js b/lib/ace/mouse/default_gutter_handler.js index 55fcf108..bf3da956 100644 --- a/lib/ace/mouse/default_gutter_handler.js +++ b/lib/ace/mouse/default_gutter_handler.js @@ -150,7 +150,8 @@ function GutterHandler(mouseHandler) { hideTooltip(); }, 50); }); - + + editor.on("changeSession", hideTooltip); } exports.GutterHandler = GutterHandler; diff --git a/lib/ace/scrollbar.js b/lib/ace/scrollbar.js index 85b69b6f..79af665a 100644 --- a/lib/ace/scrollbar.js +++ b/lib/ace/scrollbar.js @@ -47,7 +47,7 @@ var EventEmitter = require("./lib/event_emitter").EventEmitter; * * @constructor **/ -var ScrollBarV = function(parent) { +var ScrollBarV = function(parent, renderer) { this.element = dom.createElement("div"); this.element.className = "ace_scrollbar"; @@ -62,16 +62,19 @@ var ScrollBarV = function(parent) { // of 0px // in Firefox 6+ scrollbar is hidden if element has the same width as scrollbar // make element a little bit wider to retain scrollbar when page is zoomed - this.width = dom.scrollbarWidth(parent.ownerDocument); - this.fullWidth = this.width; - this.element.style.width = (this.width || 15) + 5 + "px"; + renderer.once("beforeRender", function() { + renderer.$scrollbarWidth = + this.width = dom.scrollbarWidth(parent.ownerDocument); + this.fullWidth = this.width; + this.element.style.width = (this.width || 15) + 5 + "px"; + }.bind(this)); this.setVisible(false); this.element.style.overflowY = "scroll"; event.addListener(this.element, "scroll", this.onScrollV.bind(this)); }; -var ScrollBarH = function(parent) { +var ScrollBarH = function(parent, renderer) { this.element = dom.createElement("div"); this.element.className = "ace_scrollbar-h"; @@ -86,9 +89,11 @@ var ScrollBarH = function(parent) { // of 0px // in Firefox 6+ scrollbar is hidden if element has the same width as scrollbar // make element a little bit wider to retain scrollbar when page is zoomed - this.height = dom.scrollbarWidth(parent.ownerDocument); - this.fullHeight = this.height; - this.element.style.height = (this.height || 15) + 5 + "px"; + renderer.once("beforeRender", function() { + this.height = renderer.$scrollbarWidth; + this.fullHeight = this.height; + this.element.style.height = (this.height || 15) + 5 + "px"; + }.bind(this)); this.setVisible(false); this.element.style.overflowX = "scroll"; diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index 1f641afc..88f8d79a 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -105,8 +105,8 @@ var VirtualRenderer = function(container, theme) { this.$vScroll = false; this.scrollBar = - this.scrollBarV = new ScrollBarV(this.container); - this.scrollBarH = new ScrollBarH(this.container); + this.scrollBarV = new ScrollBarV(this.container, this); + this.scrollBarH = new ScrollBarH(this.container, this); this.scrollBarV.addEventListener("scroll", function(e) { if (!_self.$scrollAnimation) _self.session.setScrollTop(e.data - _self.scrollMargin.top); @@ -210,7 +210,9 @@ var VirtualRenderer = function(container, theme) { this.setStyle("ace_nobold", !this.$allowBoldFonts); } + this.layerConfig.characterWidth = this.characterWidth = this.$textLayer.getCharacterWidth(); + this.layerConfig.lineHeight = this.lineHeight = this.$textLayer.getLineHeight(); this.$updatePrintMargin(); }; @@ -308,6 +310,8 @@ var VirtualRenderer = function(container, theme) { * **/ this.onResize = function(force, gutterWidth, width, height) { + // if (force) + // console.log("force resize requested", width, height) if (this.resizing > 2) return; else if (this.resizing > 0) @@ -318,9 +322,15 @@ var VirtualRenderer = function(container, theme) { height = this.container.clientHeight; if (!width) width = this.container.clientWidth; - var changes = this.$updateCachedSize(force, gutterWidth, width, height); + + // console.log("resizing to", width, height, JSON.stringify(this.$size)) + // setTimeout(function() { + // console.log("actual size ", this.container.clientWidth, this.container.clientHeight) + + // }.bind(this), 500) + if (!this.$size.scrollerHeight) return; @@ -347,7 +357,8 @@ var VirtualRenderer = function(container, theme) { if (this.$horizScroll) size.scrollerHeight -= this.scrollBarH.getHeight(); - this.scrollBarV.setHeight(size.scrollerHeight); + // this.scrollBarV.setHeight(size.scrollerHeight); + this.scrollBarV.element.style.bottom = this.scrollBarH.getHeight() + "px"; if (this.session) { this.session.setScrollTop(this.getScrollTop()); @@ -355,19 +366,24 @@ var VirtualRenderer = function(container, theme) { } } - if (width && (force || this.resizing > 1 || size.width != width)) { + if (width && (force || size.width != width)) { changes = this.CHANGE_SIZE; size.width = width; - - gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0; + + if (gutterWidth == null) + gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0; + + this.gutterWidth = gutterWidth; + this.scrollBarH.element.style.left = this.scroller.style.left = gutterWidth + "px"; size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBarV.getWidth()); - + + this.scrollBarH.element.style.right = this.scroller.style.right = this.scrollBarV.getWidth() + "px"; this.scroller.style.bottom = this.scrollBarH.getHeight() + "px"; - this.scrollBarH.setWidth(size.scrollerWidth); + // this.scrollBarH.element.style.setWidth(size.scrollerWidth); if (this.session && this.session.getUseWrapMode() && this.adjustWrapLimit() || force) changes = changes | this.CHANGE_FULL; @@ -376,17 +392,13 @@ var VirtualRenderer = function(container, theme) { if (changes) this._signal("resize"); - if (this.$changes) { - changes |= this.$changes; - this.$changes = 0; - } - return changes; }; this.onGutterResize = function() { var gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0; - this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height); + if (gutterWidth != this.gutterWidth) + this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height); if (this.session.getUseWrapMode() && this.adjustWrapLimit()) this.$loop.schedule(this.CHANGE_FULL); @@ -714,10 +726,15 @@ var VirtualRenderer = function(container, theme) { }; this.$renderChanges = function(changes, force) { - if (!force && (!changes || !this.session || !this.container.offsetWidth)) { - this.$changes = changes; + if ((!this.session || !this.container.offsetWidth) || (!changes && !force)) { + this.$logChanges(changes); + this.$changes |= changes; return; } + if (this.$changes) { + changes |= this.$changes; + this.$changes = 0; + } // this.$logChanges(changes); @@ -730,7 +747,7 @@ var VirtualRenderer = function(container, theme) { changes & this.CHANGE_SCROLL || changes & this.CHANGE_H_SCROLL ) - this.$computeLayerConfig(); + changes |= this.$computeLayerConfig(); // horizontal scrolling if (changes & this.CHANGE_H_SCROLL) { @@ -841,9 +858,6 @@ var VirtualRenderer = function(container, theme) { if (this.$maxLines && this.lineHeight > 1) this.$autosize(); - if (!this.$size.scrollerHeight) - return this.onResize(true); - var session = this.session; var hideScrollbars = this.$size.height <= 2 * this.lineHeight; @@ -933,12 +947,14 @@ var VirtualRenderer = function(container, theme) { this.content.style.width = longestLine + 2 * this.$padding + "px"; this.content.style.height = minHeight + "px"; + var changes = 0; // Horizontal scrollbar visibility may have changed, which changes // the client height of the scroller if (hScrollChanged || vScrollChanged) { - this.onResize(true); + changes = this.$updateCachedSize(true, this.gutterWidth, this.$size.width, this.$size.height); this._signal("scrollbarVisibilityChanged"); } + return changes; }; this.$updateLines = function() { @@ -1070,8 +1086,10 @@ var VirtualRenderer = function(container, theme) { var left = pos.left; var top = pos.top; + + var scrollTop = this.$scrollAnimation ? this.session.getScrollTop() : this.scrollTop; - if (this.scrollTop > top) { + if (scrollTop > top) { if (offset) top -= offset * this.$size.scrollerHeight; if (top == 0) @@ -1079,7 +1097,7 @@ var VirtualRenderer = function(container, theme) { else if (top == 0) top = + this.scrollMargin.bottom; this.session.setScrollTop(top); - } else if (this.scrollTop + this.$size.scrollerHeight < top + this.lineHeight) { + } else if (scrollTop + this.$size.scrollerHeight < top + this.lineHeight) { if (offset) top += offset * this.$size.scrollerHeight; this.session.setScrollTop(top + this.lineHeight - this.$size.scrollerHeight); @@ -1196,31 +1214,44 @@ var VirtualRenderer = function(container, theme) { this.animateScrolling = function(fromValue, callback) { var toValue = this.scrollTop; - if (this.$animatedScroll) { - var _self = this; - var steps = _self.$calcSteps(fromValue, toValue); - this.$scrollAnimation = {from: fromValue, to: toValue}; - - clearInterval(this.$timer); - - _self.session.setScrollTop(steps.shift()); - this.$timer = setInterval(function() { - if (steps.length) { - _self.session.setScrollTop(steps.shift()); - // trick session to think it's already scrolled to not loose toValue - _self.session.$scrollTop = toValue; - } else if (toValue != null) { - _self.session.$scrollTop = -1; - _self.session.setScrollTop(toValue); - toValue = null; - } else { - // do this on separate step to not get spurious scroll event from scrollbar - _self.$timer = clearInterval(_self.$timer); - _self.$scrollAnimation = null; - callback && callback(); - } - }, 10); + if (!this.$animatedScroll) + return; + var _self = this; + + if (fromValue == toValue) + return; + + if (this.$scrollAnimation) { + var oldSteps = this.$scrollAnimation.steps; + if (oldSteps.length) { + fromValue = oldSteps[0]; + if (fromValue == toValue) + return; + } } + + var steps = _self.$calcSteps(fromValue, toValue); + this.$scrollAnimation = {from: fromValue, to: toValue, steps: steps}; + + clearInterval(this.$timer); + + _self.session.setScrollTop(steps.shift()); + this.$timer = setInterval(function() { + if (steps.length) { + _self.session.setScrollTop(steps.shift()); + // trick session to think it's already scrolled to not loose toValue + _self.session.$scrollTop = toValue; + } else if (toValue != null) { + _self.session.$scrollTop = -1; + _self.session.setScrollTop(toValue); + toValue = null; + } else { + // do this on separate step to not get spurious scroll event from scrollbar + _self.$timer = clearInterval(_self.$timer); + _self.$scrollAnimation = null; + callback && callback(); + } + }, 10); }; /**