Skip to content

Commit 12602ca

Browse files
committed
Get procedure renaming to work correctly dynamically
i.e., while typing in the name field.
1 parent ee06205 commit 12602ca

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

block-lexical-variables/src/field_procedure.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ Blockly.AIProcedure.removeProcedureValues = function(name, workspace) {
142142
*/
143143
Blockly.AIProcedure.renameProcedure = function (newName) {
144144
// this is bound to field_textinput object
145-
var oldName = this.oldName_ || this.text_;
145+
var oldName = this.oldName_ || this.getValue();
146+
const originalNewName = newName;
146147

147148
// [lyn, 10/27/13] now check legality of identifiers
148149
newName = Blockly.LexicalVariable.makeLegalIdentifier(newName);
@@ -151,6 +152,9 @@ Blockly.AIProcedure.renameProcedure = function (newName) {
151152
var procBlocks = Blockly.AIProcedure.getAllProcedureDeclarationBlocksExcept(this.sourceBlock_);
152153
var procNames = procBlocks.map(function (decl) { return decl.getFieldValue('NAME'); });
153154
newName = Blockly.FieldLexicalVariable.nameNotIn(newName, procNames);
155+
if (newName !== originalNewName) {
156+
this.doValueUpdate_(newName);
157+
}
154158
// Rename any callers.
155159
var blocks = this.sourceBlock_.workspace.getAllBlocks();
156160
for (var x = 0; x < blocks.length; x++) {

block-lexical-variables/src/field_procedurename.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ goog.inherits(AI.Blockly.FieldProcedureName, Blockly.FieldTextInput);
5151
*/
5252
AI.Blockly.FieldProcedureName.prototype.setValue = function(newValue) {
5353
var oldValue = this.getValue();
54+
this.oldName_ = oldValue;
55+
this.doValueUpdate_(newValue);
5456
AI.Blockly.FieldProcedureName.superClass_.setValue.call(this, newValue);
5557
newValue = this.getValue();
5658
if (typeof newValue === 'string' && this.sourceBlock_) {

block-lexical-variables/src/procedures.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,11 @@ Blockly.Blocks['procedures_callnoreturn'] = {
714714
renameProcedure: function(oldName, newName) {
715715
if (!oldName ||
716716
Blockly.Names.equals(oldName, this.getFieldValue('PROCNAME'))) {
717+
const nameField = this.getField('PROCNAME');
718+
// Force the options menu to get regenerated since we might be getting
719+
// called because our defining procedure got renamed and
720+
// this.setFieldValue() will fail if it's value isn't in the options set
721+
nameField.getOptions();
717722
this.setFieldValue(newName, 'PROCNAME');
718723
}
719724
},

0 commit comments

Comments
 (0)