From f38b43419c7ae7060c071654115d7971b8753aec Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 13 May 2016 16:07:53 -0700 Subject: [PATCH] Combine horizontal and vertical flyout scrolling --- core/flyout.js | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/core/flyout.js b/core/flyout.js index dbd629514..f272636c8 100644 --- a/core/flyout.js +++ b/core/flyout.js @@ -468,39 +468,29 @@ Blockly.Flyout.prototype.scrollToStart = function() { }; /** - * Scroll the flyout up or down. + * Scroll the flyout. * @param {!Event} e Mouse wheel scroll event. * @private */ Blockly.Flyout.prototype.wheel_ = function(e) { - // Don't scroll sideways. - if (this.horizontalLayout_) { - var delta = e.deltaX; - if (delta) { - if (goog.userAgent.GECKO) { - // Firefox's deltas are a tenth that of Chrome/Safari. - delta *= 10; - } - var metrics = this.getMetrics_(); - var x = metrics.viewLeft + delta; - x = Math.min(x, metrics.contentWidth - metrics.viewWidth); - x = Math.max(x, 0); - this.scrollbar_.set(x); - } - } else { - var delta = e.deltaY; - if (delta) { - if (goog.userAgent.GECKO) { - // Firefox's deltas are a tenth that of Chrome/Safari. - delta *= 10; - } - var metrics = this.getMetrics_(); - var y = metrics.viewTop + delta; - y = Math.min(y, metrics.contentHeight - metrics.viewHeight); - y = Math.max(y, 0); - this.scrollbar_.set(y); + var delta = this.horizontalLayout_ ? e.deltaX : e.deltaY; + + if (delta) { + if (goog.userAgent.GECKO) { + // Firefox's deltas are a tenth that of Chrome/Safari. + delta *= 10; } + var metrics = this.getMetrics_(); + var pos = this.horizontalLayout_ ? metrics.viewLeft + delta : + metrics.viewTop + delta; + var limit = this.horizontalLayout_ ? + metrics.contentWidth - metrics.viewWidth : + metrics.contentHeight - metrics.viewHeight; + pos = Math.min(pos, limit); + pos = Math.max(pos, 0); + this.scrollbar_.set(pos); } + // Don't scroll the page. e.preventDefault(); // Don't propagate mousewheel event (zooming).