Fix Mutator editor block positions sometimes being out of place for an instant (#5210)

This commit is contained in:
hpnrep6
2021-08-02 13:32:22 -04:00
committed by GitHub
parent 47e4d05f8a
commit 4f7009a599

View File

@@ -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;