From 2dcb6cb68b199b45fbe5f84f65f5734fc19e7605 Mon Sep 17 00:00:00 2001 From: Rodrigo Queiro Date: Wed, 29 Jun 2016 03:11:48 +0200 Subject: [PATCH] Ignore mouseup at end of drag with isDragging (#416) This includes both block drags and workspace scrolls and fixes #404. I used isDragging rather than checking the origin of click so that it can easily be extended to the case where the flyout is scrolled by dragging a block, a la LLK/scratch-blocks#206. --- core/field.js | 2 +- core/flyout.js | 3 +-- core/icon.js | 2 +- core/workspace_svg.js | 8 ++++++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/core/field.js b/core/field.js index 0ea102fff..0e919ecd3 100644 --- a/core/field.js +++ b/core/field.js @@ -433,7 +433,7 @@ Blockly.Field.prototype.onMouseUp_ = function(e) { } else if (Blockly.isRightButton(e)) { // Right-click. return; - } else if (Blockly.dragMode_ == Blockly.DRAG_FREE) { + } else if (this.sourceBlock_.workspace.isDragging()) { // Drag operation is concluding. Don't open the editor. return; } else if (this.sourceBlock_.isEditable()) { diff --git a/core/flyout.js b/core/flyout.js index e8aa2f872..c65276fea 100644 --- a/core/flyout.js +++ b/core/flyout.js @@ -761,8 +761,7 @@ Blockly.Flyout.prototype.onMouseDown_ = function(e) { * @private */ Blockly.Flyout.prototype.onMouseUp_ = function(e) { - if (Blockly.dragMode_ != Blockly.DRAG_FREE && - !Blockly.WidgetDiv.isVisible()) { + if (!this.workspace_.isDragging() && !Blockly.WidgetDiv.isVisible()) { Blockly.Events.fire( new Blockly.Events.Ui(Blockly.Flyout.startBlock_, 'click', undefined, undefined)); diff --git a/core/icon.js b/core/icon.js index 9d2cbeaad..395c98544 100644 --- a/core/icon.js +++ b/core/icon.js @@ -124,7 +124,7 @@ Blockly.Icon.prototype.isVisible = function() { * @private */ Blockly.Icon.prototype.iconClick_ = function(e) { - if (Blockly.dragMode_ == Blockly.DRAG_FREE) { + if (this.block_.workspace.isDragging()) { // Drag operation is concluding. Don't open the editor. return; } diff --git a/core/workspace_svg.js b/core/workspace_svg.js index d857bdf21..6f5f26a1b 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -710,6 +710,14 @@ Blockly.WorkspaceSvg.prototype.moveDrag = function(e) { return goog.math.Coordinate.sum(this.dragDeltaXY_, point); }; +/** + * Is the user currently dragging a block or scrolling the workspace? + * @return {boolean} True if currently dragging or scrolling + */ +Blockly.WorkspaceSvg.prototype.isDragging = function() { + return Blockly.dragMode_ == Blockly.DRAG_FREE || this.isScrolling; +}; + /** * Handle a mouse-wheel on SVG drawing surface. * @param {!Event} e Mouse wheel event.