mirror of
https://github.com/google/blockly.git
synced 2026-03-10 07:10:11 +01:00
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.
This commit is contained in:
@@ -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_);
|
||||
|
||||
Reference in New Issue
Block a user