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,11 +134,19 @@ Blockly.Blocks['lexical_variable_get'] = { ...@@ -134,11 +134,19 @@ Blockly.Blocks['lexical_variable_get'] = {
getVars: function() { getVars: function() {
return [this.getFieldValue('VAR')]; return [this.getFieldValue('VAR')];
}, },
renameLexicalVar: function(oldName, newName) { renameLexicalVar: function(oldName, newName, oldTranslatedName, newTranslatedName) {
// console.log("Renaming lexical variable from " + oldName + " to " + newName); if (oldTranslatedName === undefined) {
// Local variables
if (oldName === this.getFieldValue('VAR')) { if (oldName === this.getFieldValue('VAR')) {
this.setFieldValue(newName, '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) { renameFree: function (freeSubstitution) {
var prefixPair = Blockly.unprefixName(this.getFieldValue('VAR')); var prefixPair = Blockly.unprefixName(this.getFieldValue('VAR'));
......
...@@ -443,7 +443,7 @@ Blockly.FieldLexicalVariable.nameNotIn = function(name, nameList) { ...@@ -443,7 +443,7 @@ Blockly.FieldLexicalVariable.nameNotIn = function(name, nameList) {
* Split name into digit suffix and prefix before it. * Split name into digit suffix and prefix before it.
* Return two-element list of prefix and suffix strings. Suffix is empty if no digits. * Return two-element list of prefix and suffix strings. Suffix is empty if no digits.
* @param {string} name Input string * @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) { Blockly.FieldLexicalVariable.prefixSuffix = function(name) {
var prefix = name; var prefix = name;
...@@ -475,7 +475,7 @@ Blockly.LexicalVariable.renameGlobal = function (newName) { ...@@ -475,7 +475,7 @@ Blockly.LexicalVariable.renameGlobal = function (newName) {
// this.sourceBlock excludes block being renamed from consideration // this.sourceBlock excludes block being renamed from consideration
// Potentially rename declaration against other occurrences // Potentially rename declaration against other occurrences
newName = Blockly.FieldLexicalVariable.nameNotIn(newName, globals); newName = Blockly.FieldLexicalVariable.nameNotIn(newName, globals);
if ((! (newName === oldName)) && this.sourceBlock_.rendered) { if (this.sourceBlock_.rendered) {
// Rename getters and setters // Rename getters and setters
if (Blockly.mainWorkspace) { if (Blockly.mainWorkspace) {
var blocks = Blockly.mainWorkspace.getAllBlocks(); var blocks = Blockly.mainWorkspace.getAllBlocks();
...@@ -484,6 +484,8 @@ Blockly.LexicalVariable.renameGlobal = function (newName) { ...@@ -484,6 +484,8 @@ Blockly.LexicalVariable.renameGlobal = function (newName) {
var renamingFunction = block.renameLexicalVar; var renamingFunction = block.renameLexicalVar;
if (renamingFunction) { if (renamingFunction) {
renamingFunction.call(block, renamingFunction.call(block,
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 + oldName,
Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX + Blockly.menuSeparator + newName); Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX + Blockly.menuSeparator + newName);
} }
......
...@@ -424,14 +424,19 @@ Blockly.WarningHandler.prototype['checkDropDownContainsValidValue'] = function(b ...@@ -424,14 +424,19 @@ Blockly.WarningHandler.prototype['checkDropDownContainsValidValue'] = function(b
for(var i=0;i<params.dropDowns.length;i++){ for(var i=0;i<params.dropDowns.length;i++){
var dropDown = block.getField(params.dropDowns[i]); var dropDown = block.getField(params.dropDowns[i]);
var dropDownList = dropDown.menuGenerator_(); var dropDownList = dropDown.menuGenerator_();
var text = dropDown.text_; var text = dropDown.getText();
var value = dropDown.getValue();
var textInDropDown = false; var textInDropDown = false;
if (dropDown.updateMutation) { if (dropDown.updateMutation) {
dropDown.updateMutation(); dropDown.updateMutation();
} }
for(var k=0;k<dropDownList.length;k++) { for(var k=0;k<dropDownList.length;k++) {
if(dropDownList[k][0] == text && text != " "){ if (dropDownList[k][1] == value && value != " ") {
textInDropDown = true; 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; 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