From 0246e2a1326ba6eee1558f0c0564afb706d27bd6 Mon Sep 17 00:00:00 2001 From: Monica Kozbial Date: Fri, 5 Mar 2021 11:34:29 -0800 Subject: [PATCH] Fix flyout metrics and workspace scroll (#4674) * Fix flyout metrics and max scroll logic in scroll * Fix horizontal scroll wheel logic --- core/flyout_horizontal.js | 13 +++++-------- core/flyout_vertical.js | 5 +---- core/workspace_svg.js | 7 ++++--- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index 6a3252948..11cbe8302 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -90,13 +90,13 @@ Blockly.HorizontalFlyout.prototype.getMetrics_ = function() { var metrics = { contentHeight: optionBox.height * this.workspace_.scale, contentWidth: optionBox.width * this.workspace_.scale, - contentTop: 0, - contentLeft: 0, + contentTop: optionBox.y, + contentLeft: optionBox.x, scrollHeight: (optionBox.height + 2 * this.MARGIN) * this.workspace_.scale, scrollWidth: (optionBox.width + 2 * this.MARGIN) * this.workspace_.scale, - scrollTop: 0, - scrollLeft: 0, + scrollTop: optionBox.y - this.MARGIN, + scrollLeft: optionBox.x - this.MARGIN, viewHeight: viewHeight, viewWidth: viewWidth, @@ -276,10 +276,7 @@ Blockly.HorizontalFlyout.prototype.wheel_ = function(e) { if (delta) { var metrics = this.getMetrics_(); - var pos = metrics.viewLeft + delta; - var limit = metrics.scrollWidth - metrics.viewWidth; - pos = Math.min(pos, limit); - pos = Math.max(pos, 0); + var pos = (metrics.viewLeft - metrics.scrollLeft) + delta; this.workspace_.scrollbar.setX(pos); // When the flyout moves from a wheel event, hide WidgetDiv and DropDownDiv. Blockly.WidgetDiv.hide(); diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index 08ad041d3..576c61b78 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -102,7 +102,7 @@ Blockly.VerticalFlyout.prototype.getMetrics_ = function() { viewHeight: viewHeight, viewWidth: viewWidth, - viewTop: -this.workspace_.scrollY + optionBox.y, + viewTop: -this.workspace_.scrollY, viewLeft: -this.workspace_.scrollX, absoluteTop: absoluteTop, @@ -267,9 +267,6 @@ Blockly.VerticalFlyout.prototype.wheel_ = function(e) { if (scrollDelta.y) { var metrics = this.getMetrics_(); var pos = (metrics.viewTop - metrics.scrollTop) + scrollDelta.y; - var limit = metrics.scrollHeight - metrics.viewHeight; - pos = Math.min(pos, limit); - pos = Math.max(pos, 0); this.workspace_.scrollbar.setY(pos); // When the flyout moves from a wheel event, hide WidgetDiv and DropDownDiv. Blockly.WidgetDiv.hide(); diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 3146c230a..8e311093e 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -2218,9 +2218,10 @@ Blockly.WorkspaceSvg.prototype.scroll = function(x, y) { // to workspace coordinates so we have to inverse them. x = Math.min(x, -metrics.scrollLeft); y = Math.min(y, -metrics.scrollTop); - var maxXScroll = metrics.scrollLeft + metrics.scrollWidth - metrics.viewWidth; - var maxYScroll = - metrics.scrollTop + metrics.scrollHeight - metrics.viewHeight; + var maxXDisplacement = Math.max(0, metrics.scrollWidth - metrics.viewWidth); + var maxXScroll = metrics.scrollLeft + maxXDisplacement; + var maxYDisplacement = Math.max(0, metrics.scrollHeight - metrics.viewHeight); + var maxYScroll = metrics.scrollTop + maxYDisplacement; x = Math.max(x, -maxXScroll); y = Math.max(y, -maxYScroll); this.scrollX = x;