Skip to content

Commit

Permalink
fix: mutators disconnecting from children instead of moving them (goo…
Browse files Browse the repository at this point in the history
…gle#6047)

* fix: mutators disconnecting from children instead of moving them

* fix: debug build
  • Loading branch information
BeksOmega authored Apr 1, 2022
1 parent 55cae6e commit 493444c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
16 changes: 11 additions & 5 deletions blocks/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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++;
}
},
Expand Down
16 changes: 11 additions & 5 deletions blocks/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_++;
Expand All @@ -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.
Expand All @@ -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);
Expand All @@ -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();
}
},
/**
Expand Down
16 changes: 11 additions & 5 deletions blocks/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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++;
}
},
Expand Down

0 comments on commit 493444c

Please sign in to comment.