Unverified Commit a6d66e17 authored by Evan W. Patton's avatar Evan W. Patton Committed by GitHub

Correct order of blocks affecting global variable references (#2368)

* Correct order of blocks affecting global variable references
* Fix renaming of global variables when keyword translated
parent 521f63e0
......@@ -134,10 +134,18 @@ Blockly.Blocks['lexical_variable_get'] = {
getVars: function() {
return [this.getFieldValue('VAR')];
},
renameLexicalVar: function(oldName, newName) {
// console.log("Renaming lexical variable from " + oldName + " to " + newName);
if (oldName === this.getFieldValue('VAR')) {
renameLexicalVar: function(oldName, newName, oldTranslatedName, newTranslatedName) {
if (oldTranslatedName === undefined) {
// Local variables
if (oldName === this.getFieldValue('VAR')) {
this.setFieldValue(newName, 'VAR');
}
} else if (oldTranslatedName && oldTranslatedName === this.fieldVar_.getText()) {
// Global variables
this.fieldVar_.setText(newTranslatedName);
if (oldName === newName) {
this.setFieldValue(newName, 'VAR');
}
}
},
renameFree: function (freeSubstitution) {
......
......@@ -443,7 +443,7 @@ Blockly.FieldLexicalVariable.nameNotIn = function(name, nameList) {
* Split name into digit suffix and prefix before it.
* Return two-element list of prefix and suffix strings. Suffix is empty if no digits.
* @param {string} name Input string
* @return {string list} Two-element list of prefix and suffix
* @return {string[]} Two-element list of prefix and suffix
*/
Blockly.FieldLexicalVariable.prefixSuffix = function(name) {
var prefix = name;
......@@ -475,7 +475,7 @@ Blockly.LexicalVariable.renameGlobal = function (newName) {
// this.sourceBlock excludes block being renamed from consideration
// Potentially rename declaration against other occurrences
newName = Blockly.FieldLexicalVariable.nameNotIn(newName, globals);
if ((! (newName === oldName)) && this.sourceBlock_.rendered) {
if (this.sourceBlock_.rendered) {
// Rename getters and setters
if (Blockly.mainWorkspace) {
var blocks = Blockly.mainWorkspace.getAllBlocks();
......@@ -484,8 +484,10 @@ Blockly.LexicalVariable.renameGlobal = function (newName) {
var renamingFunction = block.renameLexicalVar;
if (renamingFunction) {
renamingFunction.call(block,
Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX + Blockly.menuSeparator + oldName,
Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX + Blockly.menuSeparator + newName);
Blockly.GLOBAL_KEYWORD + Blockly.menuSeparator + oldName,
Blockly.GLOBAL_KEYWORD + Blockly.menuSeparator + newName,
Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX + Blockly.menuSeparator + oldName,
Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX + Blockly.menuSeparator + newName);
}
}
}
......
......@@ -424,14 +424,19 @@ Blockly.WarningHandler.prototype['checkDropDownContainsValidValue'] = function(b
for(var i=0;i<params.dropDowns.length;i++){
var dropDown = block.getField(params.dropDowns[i]);
var dropDownList = dropDown.menuGenerator_();
var text = dropDown.text_;
var text = dropDown.getText();
var value = dropDown.getValue();
var textInDropDown = false;
if (dropDown.updateMutation) {
dropDown.updateMutation();
}
for(var k=0;k<dropDownList.length;k++) {
if(dropDownList[k][0] == text && text != " "){
if (dropDownList[k][1] == value && value != " ") {
textInDropDown = true;
// A mismatch in the untranslated value and translated text can be corrected.
if (dropDownList[k][0] != text) {
dropDown.setText(dropDownList[k][0]);
}
break;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment