From 392d25eb39bda1d7ff2993500115dbd2173484cf Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Tue, 18 Feb 2020 16:01:18 -0800 Subject: [PATCH 1/2] fix: Break breaking undo. --- blocks/loops.js | 27 +++++++++++++-------------- core/block_svg.js | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/blocks/loops.js b/blocks/loops.js index 57ef12aac..0163350d5 100644 --- a/blocks/loops.js +++ b/blocks/loops.js @@ -327,24 +327,23 @@ Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN = { /** * Called whenever anything on the workspace changes. * Add warning if this flow block is not nested inside a loop. - * @param {!Blockly.Events.Abstract} _e Change event. + * @param {!Blockly.Events.Abstract} e Change event. * @this {Blockly.Block} */ - onchange: function(_e) { - if (!this.workspace.isDragging || this.workspace.isDragging()) { + onchange: function(e) { + if (!this.workspace.isDragging || this.workspace.isDragging() || + e.type != Blockly.Events.BLOCK_MOVE || e.blockId != this.id) { return; // Don't change state at the start of a drag. } - if (Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN - .getSurroundLoop(this)) { - this.setWarningText(null); - if (!this.isInFlyout) { - this.setEnabled(true); - } - } else { - this.setWarningText(Blockly.Msg['CONTROLS_FLOW_STATEMENTS_WARNING']); - if (!this.isInFlyout && !this.getInheritedDisabled()) { - this.setEnabled(false); - } + var enabled = Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN + .getSurroundLoop(this); + this.setWarningText(enabled ? null : + Blockly.Msg['CONTROLS_FLOW_STATEMENTS_WARNING']); + if (!this.isInFlyout) { + var group = Blockly.Events.getGroup(); + Blockly.Events.setGroup(e.group); + this.setEnabled(enabled); + Blockly.Events.setGroup(group); } } }; diff --git a/core/block_svg.js b/core/block_svg.js index 65741cfe4..fe9815d6b 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -1180,7 +1180,7 @@ Blockly.BlockSvg.prototype.setDisabled = function(disabled) { Blockly.BlockSvg.prototype.setEnabled = function(enabled) { if (this.isEnabled() != enabled) { Blockly.BlockSvg.superClass_.setEnabled.call(this, enabled); - if (this.rendered) { + if (this.rendered && !this.getInheritedDisabled()) { this.updateDisabled(); } } From 5445cf4cf823a8dbbcae5f356776733ae5e6193e Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Wed, 19 Feb 2020 14:40:28 -0800 Subject: [PATCH 2/2] Add comments to break block change listener. --- blocks/loops.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/blocks/loops.js b/blocks/loops.js index 0163350d5..d6fb2f2f6 100644 --- a/blocks/loops.js +++ b/blocks/loops.js @@ -331,9 +331,13 @@ Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN = { * @this {Blockly.Block} */ onchange: function(e) { + // Don't change state if: + // * It's at the start of a drag. + // * It's not a move event. + // * Or the moving block is not this block. if (!this.workspace.isDragging || this.workspace.isDragging() || e.type != Blockly.Events.BLOCK_MOVE || e.blockId != this.id) { - return; // Don't change state at the start of a drag. + return; } var enabled = Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN .getSurroundLoop(this); @@ -341,6 +345,7 @@ Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN = { Blockly.Msg['CONTROLS_FLOW_STATEMENTS_WARNING']); if (!this.isInFlyout) { var group = Blockly.Events.getGroup(); + // Makes it so the move and the disable event get undone together. Blockly.Events.setGroup(e.group); this.setEnabled(enabled); Blockly.Events.setGroup(group);