From 304e167c550400bce35b2883a9bfba2ba5fd3f37 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Thu, 17 Aug 2023 17:13:00 +0000 Subject: [PATCH 1/2] fix: incorrectly reconnecting child blocks during mutation --- plugins/block-shareable-procedures/src/blocks.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/block-shareable-procedures/src/blocks.ts b/plugins/block-shareable-procedures/src/blocks.ts index 41a62c8185..dd773f9df9 100644 --- a/plugins/block-shareable-procedures/src/blocks.ts +++ b/plugins/block-shareable-procedures/src/blocks.ts @@ -996,7 +996,6 @@ const procedureCallerUpdateShapeMixin = { * data model. */ updateParameters_: function() { - this.updateArgsMap_(); this.deleteAllArgInputs_(); this.addParametersLabel__(); this.createArgInputs_(); @@ -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()); + } } }, @@ -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. From a5f9b0940fa6f1492ac03ff2da89ff2a35de4e9f Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Thu, 17 Aug 2023 18:07:00 +0000 Subject: [PATCH 2/2] chore: tick clock to fix tests --- .../block-shareable-procedures/test/procedure_blocks.mocha.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/block-shareable-procedures/test/procedure_blocks.mocha.js b/plugins/block-shareable-procedures/test/procedure_blocks.mocha.js index 9839cefb07..b2c770a8b2 100644 --- a/plugins/block-shareable-procedures/test/procedure_blocks.mocha.js +++ b/plugins/block-shareable-procedures/test/procedure_blocks.mocha.js @@ -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); @@ -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();