mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-28 22:10:31 -04:00
Stop new 'do procedure' defs from renaming existing callers.
This commit is contained in:
parent
2dab19c015
commit
57390fd744
1 changed files with 17 additions and 12 deletions
|
@ -89,7 +89,7 @@ Blockly.Procedures.findLegalName = function(name, block) {
|
|||
// Flyouts can have multiple procedures called 'do something'.
|
||||
return name;
|
||||
}
|
||||
while (!Blockly.Procedures.isLegalName(name, block.workspace, block)) {
|
||||
while (!Blockly.Procedures.isLegalName_(name, block.workspace, block)) {
|
||||
// Collision with another procedure.
|
||||
var r = name.match(/^(.*?)(\d+)$/);
|
||||
if (!r) {
|
||||
|
@ -109,8 +109,9 @@ Blockly.Procedures.findLegalName = function(name, block) {
|
|||
* @param {Blockly.Block=} opt_exclude Optional block to exclude from
|
||||
* comparisons (one doesn't want to collide with oneself).
|
||||
* @return {boolean} True if the name is legal.
|
||||
* @private
|
||||
*/
|
||||
Blockly.Procedures.isLegalName = function(name, workspace, opt_exclude) {
|
||||
Blockly.Procedures.isLegalName_ = function(name, workspace, opt_exclude) {
|
||||
var blocks = workspace.getAllBlocks();
|
||||
// Iterate through every block and check the name.
|
||||
for (var i = 0; i < blocks.length; i++) {
|
||||
|
@ -129,24 +130,28 @@ Blockly.Procedures.isLegalName = function(name, workspace, opt_exclude) {
|
|||
|
||||
/**
|
||||
* Rename a procedure. Called by the editable field.
|
||||
* @param {string} text The proposed new name.
|
||||
* @param {string} name The proposed new name.
|
||||
* @return {string} The accepted name.
|
||||
* @this {!Blockly.Field}
|
||||
*/
|
||||
Blockly.Procedures.rename = function(text) {
|
||||
Blockly.Procedures.rename = function(name) {
|
||||
// Strip leading and trailing whitespace. Beyond this, all names are legal.
|
||||
text = text.replace(/^[\s\xa0]+|[\s\xa0]+$/g, '');
|
||||
name = name.replace(/^[\s\xa0]+|[\s\xa0]+$/g, '');
|
||||
|
||||
// Ensure two identically-named procedures don't exist.
|
||||
text = Blockly.Procedures.findLegalName(text, this.sourceBlock_);
|
||||
// Rename any callers.
|
||||
var blocks = this.sourceBlock_.workspace.getAllBlocks();
|
||||
for (var i = 0; i < blocks.length; i++) {
|
||||
if (blocks[i].renameProcedure) {
|
||||
blocks[i].renameProcedure(this.text_, text);
|
||||
var legalName = Blockly.Procedures.findLegalName(name, this.sourceBlock_);
|
||||
var oldName = this.text_;
|
||||
console.log(oldName + ' ' + name + ' ' + legalName)
|
||||
if (oldName != name && oldName != legalName) {
|
||||
// Rename any callers.
|
||||
var blocks = this.sourceBlock_.workspace.getAllBlocks();
|
||||
for (var i = 0; i < blocks.length; i++) {
|
||||
if (blocks[i].renameProcedure) {
|
||||
blocks[i].renameProcedure(oldName, legalName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return text;
|
||||
return legalName;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue