From 455a5bb64cefe945730fb88db971268eb476b9aa Mon Sep 17 00:00:00 2001 From: "Evan W. Patton" Date: Fri, 26 May 2017 23:46:36 -0400 Subject: [PATCH] Add check to prevent spawning multiple blocks Some App Inventor users were reporting issues where multiple blocks were being created when dragging from the flyout. This commit adds a lastBlockCreated field on the flyout that is used to detect whether a creation operation has occurred since the last time the flyout was opened. This field is cleared as part of clearOldBlocks_, which is called during each show operation. --- core/flyout.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/flyout.js b/core/flyout.js index adb005934..6d755cab2 100644 --- a/core/flyout.js +++ b/core/flyout.js @@ -937,6 +937,7 @@ Blockly.Flyout.prototype.clearOldBlocks_ = function() { button.dispose(); } this.buttons_.length = 0; + this.lastBlockCreated = null; }; /** @@ -1051,8 +1052,12 @@ Blockly.Flyout.prototype.onMouseUp_ = function(e) { // This was a click, not a drag. End the gesture. Blockly.Touch.clearTouchIdentifier(); if (this.autoClose) { - this.createBlockFunc_(Blockly.Flyout.startBlock_)( + if (this.lastBlockCreated == null) { + this.createBlockFunc_(Blockly.Flyout.startBlock_)( Blockly.Flyout.startDownEvent_); + } else { + console.warn(new Error('Rejecting multiple block creation in flyout.')); + } } else if (!Blockly.WidgetDiv.isVisible()) { Blockly.Events.fire( new Blockly.Events.Ui(Blockly.Flyout.startBlock_, 'click', @@ -1115,7 +1120,10 @@ Blockly.Flyout.prototype.onMouseMoveBlock_ = function(e) { var dy = e.clientY - Blockly.Flyout.startDownEvent_.clientY; var createBlock = this.determineDragIntention_(dx, dy); - if (createBlock) { + if (this.lastBlockCreated != null) { + Blockly.longStop_(); + console.warn(new Error('Rejecting multiple block creation in flyout.')); + } else if (createBlock) { Blockly.longStop_(); this.createBlockFunc_(Blockly.Flyout.startBlock_)( Blockly.Flyout.startDownEvent_);