diff --git a/core/mutator.js b/core/mutator.js index 1bd6d0988..8379a79f4 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -352,6 +352,8 @@ Blockly.Mutator.prototype.setVisible = function(visible) { this.resizeBubble_(); // When the mutator's workspace changes, update the source block. this.workspace_.addChangeListener(this.workspaceChanged_.bind(this)); + // Update the source block immediately after the bubble becomes visible. + this.updateWorkspace_(); this.applyColour(); } else { // Dispose of the bubble. @@ -371,18 +373,24 @@ Blockly.Mutator.prototype.setVisible = function(visible) { }; /** - * Update the source block when the mutator's blocks are changed. - * Bump down any block that's too high. * Fired whenever a change is made to the mutator's workspace. * @param {!Blockly.Events.Abstract} e Custom data for event. * @private */ Blockly.Mutator.prototype.workspaceChanged_ = function(e) { - if (e.isUiEvent || - (e.type == Blockly.Events.CHANGE && e.element == 'disabled')) { - return; + if (!(e.isUiEvent || + (e.type == Blockly.Events.CHANGE && e.element == 'disabled') || + e.type == Blockly.Events.CREATE)) { + this.updateWorkspace_(); } +}; +/** + * Updates the source block when the mutator's blocks are changed. + * Bump down any block that's too high. + * @private + */ +Blockly.Mutator.prototype.updateWorkspace_ = function() { if (!this.workspace_.isDragging()) { var blocks = this.workspace_.getTopBlocks(false); var MARGIN = 20;