From c7a359a8424287f139752573a27a8a6eb97cb7b3 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Wed, 23 Mar 2022 08:48:40 -0700 Subject: [PATCH] fix: undo/redo for auto disabling if-return blocks (#6018) * fix: undo/redo for auto disabling if-return blocks * fix: update inline docs --- blocks/loops.js | 2 +- blocks/procedures.js | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/blocks/loops.js b/blocks/loops.js index e6772c82ead..4578fc46ff9 100644 --- a/blocks/loops.js +++ b/blocks/loops.js @@ -342,7 +342,7 @@ const 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 {!AbstractEvent} e Change event. + * @param {!AbstractEvent} e Move event. * @this {Block} */ onchange: function(e) { diff --git a/blocks/procedures.js b/blocks/procedures.js index e5ca8e80640..8e652ed3906 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -1139,11 +1139,12 @@ blocks['procedures_ifreturn'] = { /** * Called whenever anything on the workspace changes. * Add warning if this flow block is not nested inside a loop. - * @param {!AbstractEvent} _e Change event. + * @param {!AbstractEvent} e Move event. * @this {Block} */ - onchange: function(_e) { - if (this.workspace.isDragging && this.workspace.isDragging()) { + onchange: function(e) { + if (this.workspace.isDragging && this.workspace.isDragging() || + e.type !== Events.BLOCK_MOVE) { return; // Don't change state at the start of a drag. } let legal = false; @@ -1171,14 +1172,15 @@ blocks['procedures_ifreturn'] = { this.hasReturnValue_ = true; } this.setWarningText(null); - if (!this.isInFlyout) { - this.setEnabled(true); - } } else { this.setWarningText(Msg['PROCEDURES_IFRETURN_WARNING']); - if (!this.isInFlyout && !this.getInheritedDisabled()) { - this.setEnabled(false); - } + } + if (!this.isInFlyout) { + const group = Events.getGroup(); + // Makes it so the move and the disable event get undone together. + Events.setGroup(e.group); + this.setEnabled(legal); + Events.setGroup(group); } }, /**