diff --git a/blocks/lists.js b/blocks/lists.js index 46975d6cd71..dfff7b9f95d 100644 --- a/blocks/lists.js +++ b/blocks/lists.js @@ -198,10 +198,13 @@ blocks['lists_create_with'] = { let itemBlock = containerBlock.getInputTargetBlock('STACK'); // Count number of inputs. const connections = []; - while (itemBlock && !itemBlock.isInsertionMarker()) { + while (itemBlock) { + if (itemBlock.isInsertionMarker()) { + itemBlock = itemBlock.getNextBlock(); + continue; + } connections.push(itemBlock.valueConnection_); - itemBlock = - itemBlock.nextConnection && itemBlock.nextConnection.targetBlock(); + itemBlock = itemBlock.getNextBlock(); } // Disconnect any children that don't belong. for (let i = 0; i < this.itemCount_; i++) { @@ -226,10 +229,13 @@ blocks['lists_create_with'] = { let itemBlock = containerBlock.getInputTargetBlock('STACK'); let i = 0; while (itemBlock) { + if (itemBlock.isInsertionMarker()) { + itemBlock = itemBlock.getNextBlock(); + continue; + } const input = this.getInput('ADD' + i); itemBlock.valueConnection_ = input && input.connection.targetConnection; - itemBlock = - itemBlock.nextConnection && itemBlock.nextConnection.targetBlock(); + itemBlock = itemBlock.getNextBlock(); i++; } }, diff --git a/blocks/logic.js b/blocks/logic.js index 04e1572beee..9c3ae781e48 100644 --- a/blocks/logic.js +++ b/blocks/logic.js @@ -394,7 +394,11 @@ const CONTROLS_IF_MUTATOR_MIXIN = { const valueConnections = [null]; const statementConnections = [null]; let elseStatementConnection = null; - while (clauseBlock && !clauseBlock.isInsertionMarker()) { + while (clauseBlock) { + if (clauseBlock.isInsertionMarker()) { + clauseBlock = clauseBlock.getNextBlock(); + continue; + } switch (clauseBlock.type) { case 'controls_if_elseif': this.elseifCount_++; @@ -408,8 +412,7 @@ const CONTROLS_IF_MUTATOR_MIXIN = { default: throw TypeError('Unknown block type: ' + clauseBlock.type); } - clauseBlock = clauseBlock.nextConnection && - clauseBlock.nextConnection.targetBlock(); + clauseBlock = clauseBlock.getNextBlock(); } this.updateShape_(); // Reconnect any child blocks. @@ -425,6 +428,10 @@ const CONTROLS_IF_MUTATOR_MIXIN = { let clauseBlock = containerBlock.nextConnection.targetBlock(); let i = 1; while (clauseBlock) { + if (clauseBlock.isInsertionMarker()) { + clauseBlock = clauseBlock.getNextBlock(); + continue; + } switch (clauseBlock.type) { case 'controls_if_elseif': { const inputIf = this.getInput('IF' + i); @@ -445,8 +452,7 @@ const CONTROLS_IF_MUTATOR_MIXIN = { default: throw TypeError('Unknown block type: ' + clauseBlock.type); } - clauseBlock = clauseBlock.nextConnection && - clauseBlock.nextConnection.targetBlock(); + clauseBlock = clauseBlock.getNextBlock(); } }, /** diff --git a/blocks/text.js b/blocks/text.js index efaebb5008e..5c3c2811076 100644 --- a/blocks/text.js +++ b/blocks/text.js @@ -781,10 +781,13 @@ const TEXT_JOIN_MUTATOR_MIXIN = { let itemBlock = containerBlock.getInputTargetBlock('STACK'); // Count number of inputs. const connections = []; - while (itemBlock && !itemBlock.isInsertionMarker()) { + while (itemBlock) { + if (itemBlock.isInsertionMarker()) { + itemBlock = itemBlock.getNextBlock(); + continue; + } connections.push(itemBlock.valueConnection_); - itemBlock = - itemBlock.nextConnection && itemBlock.nextConnection.targetBlock(); + itemBlock = itemBlock.getNextBlock(); } // Disconnect any children that don't belong. for (let i = 0; i < this.itemCount_; i++) { @@ -809,10 +812,13 @@ const TEXT_JOIN_MUTATOR_MIXIN = { let itemBlock = containerBlock.getInputTargetBlock('STACK'); let i = 0; while (itemBlock) { + if (itemBlock.isInsertionMarker()) { + itemBlock = itemBlock.getNextBlock(); + continue; + } const input = this.getInput('ADD' + i); itemBlock.valueConnection_ = input && input.connection.targetConnection; - itemBlock = - itemBlock.nextConnection && itemBlock.nextConnection.targetBlock(); + itemBlock = itemBlock.getNextBlock(); i++; } },