From c44909baa3237c929ecf6ac27717f92a365ab862 Mon Sep 17 00:00:00 2001 From: "Evan W. Patton" Date: Sun, 28 May 2017 15:32:34 -0400 Subject: [PATCH] Add mitigations for reported Blockly update issues 1. Set lastBlockCreated only if the flyout is not a mutator flyout. 2. Only hide workspace scrollbars for the drawer and backpack are opened, not mutator workspaces. 3. Terminate the flyout's drag operations immediately before creating a new block. 4. Catch any exceptions in Flyout.prototype.hide that might prevent proper clean up of the event listeners. --- core/flyout.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/core/flyout.js b/core/flyout.js index 6d755cab2..15db87b00 100644 --- a/core/flyout.js +++ b/core/flyout.js @@ -723,13 +723,17 @@ Blockly.Flyout.prototype.hide = function() { if (!this.isVisible()) { return; } - if (Blockly.mainWorkspace) { + if (Blockly.mainWorkspace && !this.targetWorkspace_.isMutator) { Blockly.mainWorkspace.setScrollbarsVisible(true); } this.setVisible(false); // Delete all the event listeners. for (var x = 0, listen; listen = this.listeners_[x]; x++) { - Blockly.unbindEvent_(listen); + try { + Blockly.unbindEvent_(listen); + } catch(e) { + console.warn('Unable to unbind event listener during flyout.hide()', e); + } } this.listeners_.length = 0; if (this.reflowWrapper_) { @@ -746,7 +750,7 @@ Blockly.Flyout.prototype.hide = function() { * Variables and procedures have a custom set of blocks. */ Blockly.Flyout.prototype.show = function(xmlList) { - if (Blockly.mainWorkspace) { + if (Blockly.mainWorkspace && !this.targetWorkspace_.isMutator) { Blockly.mainWorkspace.setScrollbarsVisible(false); // hide parent's scrollbars } this.workspace_.setResizesEnabled(false); @@ -1057,6 +1061,7 @@ Blockly.Flyout.prototype.onMouseUp_ = function(e) { Blockly.Flyout.startDownEvent_); } else { console.warn(new Error('Rejecting multiple block creation in flyout.')); + this.hide(); } } else if (!Blockly.WidgetDiv.isVisible()) { Blockly.Events.fire( @@ -1123,6 +1128,10 @@ Blockly.Flyout.prototype.onMouseMoveBlock_ = function(e) { if (this.lastBlockCreated != null) { Blockly.longStop_(); console.warn(new Error('Rejecting multiple block creation in flyout.')); + Blockly.Flyout.terminateDrag_(); + if (this.autoClose) { + this.hide(); + } } else if (createBlock) { Blockly.longStop_(); this.createBlockFunc_(Blockly.Flyout.startBlock_)( @@ -1219,7 +1228,12 @@ Blockly.Flyout.prototype.createBlockFunc_ = function(originBlock) { // workspace. flyout.targetWorkspace_.setResizesEnabled(false); try { + Blockly.Flyout.terminateDrag_(); var block = flyout.placeNewBlock_(originBlock); + if (flyout.autoClose) { + // save this block as the last created block for this instantiation of the flyout + flyout.lastBlockCreated = block; + } } finally { Blockly.Events.enable(); }