Fix flyout metrics and workspace scroll (#4674)

* Fix flyout metrics and max scroll logic in scroll

* Fix horizontal scroll wheel logic
This commit is contained in:
Monica Kozbial
2021-03-05 11:34:29 -08:00
committed by GitHub
parent 63d26dc186
commit 0246e2a132
3 changed files with 10 additions and 15 deletions

View File

@@ -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();

View File

@@ -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();

View File

@@ -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;