Skip to content

Commit

Permalink
fix: shareable procedures incorrectly reconnecting caller child block…
Browse files Browse the repository at this point in the history
…s during mutation for (#1865)

* fix: incorrectly reconnecting child blocks during mutation

* chore: tick clock to fix tests
  • Loading branch information
BeksOmega authored Aug 17, 2023
1 parent 22d986a commit c0ce651
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 7 additions & 3 deletions plugins/block-shareable-procedures/src/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,6 @@ const procedureCallerUpdateShapeMixin = {
* data model.
*/
updateParameters_: function() {
this.updateArgsMap_();
this.deleteAllArgInputs_();
this.addParametersLabel__();
this.createArgInputs_();
Expand All @@ -1009,9 +1008,13 @@ const procedureCallerUpdateShapeMixin = {
* of this caller block.
*/
updateArgsMap_: function() {
for (const [i, p] of this.prevParams_.entries()) {
for (const [i, p] of this.getProcedureModel().getParameters().entries()) {
const target = this.getInputTargetBlock(`ARG${i}`);
if (target) this.argsMap_.set(p.getId(), target);
if (target) {
this.argsMap_.set(p.getId(), target);
} else {
this.argsMap_.delete(p.getId());
}
}
},

Expand Down Expand Up @@ -1102,6 +1105,7 @@ const procedureCallerOnChangeMixin = {
if (this.disposed || this.workspace.isFlyout) return;
// Blockly.Events not generated by user. Skip handling.
if (!event.recordUndo) return;
if (event.type === Blockly.Events.BLOCK_MOVE) this.updateArgsMap_();
if (event.type !== Blockly.Events.BLOCK_CREATE) return;
if (event.blockId !== this.id && event.ids.indexOf(this.id) === -1) return;
// We already found our model, which means we don't need to create a block.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ suite('Procedures', function() {
.connect(rowBlock1.outputConnection);
callBlock.getInput('ARG1').connection
.connect(rowBlock2.outputConnection);
globalThis.clock.runAll();

procModel.deleteParameter(1);
procModel.insertParameter(param2, 0);
Expand Down Expand Up @@ -1033,6 +1034,7 @@ suite('Procedures', function() {
.connect(block1.outputConnection);
callBlock.getInput('ARG1').connection
.connect(block2.outputConnection);
globalThis.clock.runAll();

// Reorder the parameters.
paramBlock2.previousConnection.disconnect();
Expand Down

0 comments on commit c0ce651

Please sign in to comment.