diff --git a/packages/blockly/blocks/procedures.ts b/packages/blockly/blocks/procedures.ts index 9493a2dc035..8af8825d251 100644 --- a/packages/blockly/blocks/procedures.ts +++ b/packages/blockly/blocks/procedures.ts @@ -712,14 +712,32 @@ const PROCEDURES_MUTATORARGUMENT = { sourceBlock.workspace; const blocks = workspace.getAllBlocks(false); const caselessName = varName.toLowerCase(); + const usedNames = []; + let isDuplicate = false; for (let i = 0; i < blocks.length; i++) { if (blocks[i].id === this.getSourceBlock()!.id) { continue; } // Other blocks values may not be set yet when this is loaded. const otherVar = blocks[i].getFieldValue('NAME'); - if (otherVar && otherVar.toLowerCase() === caselessName) { + if (otherVar) { + if (!this.editingInteractively) { + usedNames.push(otherVar); + } + if (otherVar.toLowerCase() === caselessName) { + isDuplicate = true; + } + } + } + + if (isDuplicate) { + if (this.editingInteractively) { return null; + } else { + varName = Variables.generateUniqueNameFromOptions( + Procedures.DEFAULT_ARG, + usedNames, + ); } }