From 094418f92868a4f0bcd8925e079e230329ffaa5d Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 13 Dec 2018 08:11:16 -0800 Subject: [PATCH 1/2] Reconnects child blocks when an undo is done on an else block --- blocks/logic.js | 50 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/blocks/logic.js b/blocks/logic.js index 01f4e55b6..f115224bd 100644 --- a/blocks/logic.js +++ b/blocks/logic.js @@ -331,7 +331,7 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = { domToMutation: function(xmlElement) { this.elseifCount_ = parseInt(xmlElement.getAttribute('elseif'), 10) || 0; this.elseCount_ = parseInt(xmlElement.getAttribute('else'), 10) || 0; - this.updateShape_(); + this.rebuildShape_(); }, /** * Populate the mutator's dialog with this block's components. @@ -388,11 +388,8 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = { } this.updateShape_(); // Reconnect any child blocks. - for (var i = 1; i <= this.elseifCount_; i++) { - Blockly.Mutator.reconnect(valueConnections[i], this, 'IF' + i); - Blockly.Mutator.reconnect(statementConnections[i], this, 'DO' + i); - } - Blockly.Mutator.reconnect(elseStatementConnection, this, 'ELSE'); + this.reconnectChildBlocks_(valueConnections, statementConnections, + elseStatementConnection); }, /** * Store pointers to any connected child blocks. @@ -425,6 +422,30 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = { clauseBlock.nextConnection.targetBlock(); } }, + /** + * Reconstructs the block with all child blocks attached. + * Fixes issue #2037. + */ + rebuildShape_: function() { + var valueConnections = [null]; + var statementConnections = [null]; + var elseStatementConnection = null; + + if (this.getInput('ELSE')) { + elseStatementConnection = this.getInput('ELSE').connection.targetConnection; + } + var i = 1; + while (this.getInput('IF' + i)) { + var inputIf = this.getInput('IF' + i); + var inputDo = this.getInput('DO' + i); + valueConnections.push(inputIf.connection.targetConnection); + statementConnections.push(inputDo.connection.targetConnection); + i++; + } + this.updateShape_(); + this.reconnectChildBlocks_(valueConnections, statementConnections, + elseStatementConnection); + }, /** * Modify this block to have the correct number of inputs. * @this Blockly.Block @@ -453,6 +474,23 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = { this.appendStatementInput('ELSE') .appendField(Blockly.Msg['CONTROLS_IF_MSG_ELSE']); } + }, + /** + * Reconnects child blocks. + * @param {!Array} valueConnections List of value + * connectsions for if input. + * @param {!Array} statementConnections List of + * statement connections for do input. + * @param {?Blockly.RenderedConnection} elseStatementConnection Statement + * connection for else input. + */ + reconnectChildBlocks_: function(valueConnections, statementConnections, + elseStatementConnection) { + for (var i = 1; i <= this.elseifCount_; i++) { + Blockly.Mutator.reconnect(valueConnections[i], this, 'IF' + i); + Blockly.Mutator.reconnect(statementConnections[i], this, 'DO' + i); + } + Blockly.Mutator.reconnect(elseStatementConnection, this, 'ELSE'); } }; From 3bf933720597b55c69edb83d739733f101869988 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 13 Dec 2018 10:32:38 -0800 Subject: [PATCH 2/2] Fixed comment --- blocks/logic.js | 1 - 1 file changed, 1 deletion(-) diff --git a/blocks/logic.js b/blocks/logic.js index f115224bd..e904085c6 100644 --- a/blocks/logic.js +++ b/blocks/logic.js @@ -424,7 +424,6 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = { }, /** * Reconstructs the block with all child blocks attached. - * Fixes issue #2037. */ rebuildShape_: function() { var valueConnections = [null];