Commit 837b3c83 authored by Evan W. Patton's avatar Evan W. Patton Committed by Susan Rati Lane

Wrap typeblock updates in an event group (#1958)

Change-Id: Ife5cf5abdbaa2a0498ed018c4ab7a6398236a2da
parent efc47714
......@@ -484,7 +484,7 @@ Blockly.TypeBlock.prototype.createAutoComplete_ = function(inputText){
var numberMatch = numberReg.exec(blockName);
var textReg = new RegExp('^[\"|\']+', 'g');
var textMatch = textReg.exec(blockName);
if (numberMatch && numberMatch.length > 0){
if (numberMatch && numberMatch.length > 0) {
blockToCreate = {
canonicName: 'math_number',
dropDown: {
......@@ -492,8 +492,7 @@ Blockly.TypeBlock.prototype.createAutoComplete_ = function(inputText){
value: blockName
}
};
}
else if (textMatch && textMatch.length === 1){
} else if (textMatch && textMatch.length === 1) {
blockToCreate = {
canonicName: 'text',
dropDown: {
......@@ -501,21 +500,23 @@ Blockly.TypeBlock.prototype.createAutoComplete_ = function(inputText){
value: blockName.substring(1)
}
};
}
else
} else {
return; // block does not exist: return
}
}
var blockToCreateName = '';
var block;
if (blockToCreate.dropDown){ //All blocks should have a dropDown property, even if empty
Blockly.Events.setGroup(true);
try {
if (blockToCreate.dropDown) { //All blocks should have a dropDown property, even if empty
blockToCreateName = blockToCreate.canonicName;
// components have mutator attributes we need to deal with. We can also add these for special blocks
// e.g., this is done for create empty list
if(!goog.object.isEmpty(blockToCreate.mutatorAttributes)) {
if (!goog.object.isEmpty(blockToCreate.mutatorAttributes)) {
//construct xml
var xmlString = '<xml><block type="' + blockToCreateName + '"><mutation ';
for(var attributeName in blockToCreate.mutatorAttributes) {
for (var attributeName in blockToCreate.mutatorAttributes) {
xmlString += attributeName + '="' + blockToCreate.mutatorAttributes[attributeName] + '" ';
}
......@@ -532,13 +533,13 @@ Blockly.TypeBlock.prototype.createAutoComplete_ = function(inputText){
}
}
if (blockToCreate.dropDown.titleName && blockToCreate.dropDown.value){
if (blockToCreate.dropDown.titleName && blockToCreate.dropDown.value) {
block.setFieldValue(blockToCreate.dropDown.value, blockToCreate.dropDown.titleName);
// change type checking for split blocks
if(blockToCreate.dropDown.value == 'SPLITATFIRST' || blockToCreate.dropDown.value == 'SPLIT') {
block.getInput("AT").setCheck(Blockly.Blocks.Utilities.YailTypeToBlocklyType("text",Blockly.Blocks.Utilities.INPUT));
} else if(blockToCreate.dropDown.value == 'SPLITATFIRSTOFANY' || blockToCreate.dropDown.value == 'SPLITATANY') {
block.getInput("AT").setCheck(Blockly.Blocks.Utilities.YailTypeToBlocklyType("list",Blockly.Blocks.Utilities.INPUT));
if (blockToCreate.dropDown.value == 'SPLITATFIRST' || blockToCreate.dropDown.value == 'SPLIT') {
block.getInput("AT").setCheck(Blockly.Blocks.Utilities.YailTypeToBlocklyType("text", Blockly.Blocks.Utilities.INPUT));
} else if (blockToCreate.dropDown.value == 'SPLITATFIRSTOFANY' || blockToCreate.dropDown.value == 'SPLITATANY') {
block.getInput("AT").setCheck(Blockly.Blocks.Utilities.YailTypeToBlocklyType("list", Blockly.Blocks.Utilities.INPUT));
}
}
} else {
......@@ -552,14 +553,13 @@ Blockly.TypeBlock.prototype.createAutoComplete_ = function(inputText){
selectedX = selectedXY.x;
selectedY = selectedXY.y;
self.connectIfPossible(blockSelected, block);
if(!block.parentBlock_){
if (!block.parentBlock_) {
//Place it close but a bit out of the way from the one we created.
block.moveBy(Blockly.selected.getRelativeToSurfaceXY().x + 110,
Blockly.selected.getRelativeToSurfaceXY().y + 50);
}
block.select();
}
else {
} else {
//calculate positions relative to the view and the latest click
var left = self.workspace_.latestClick.x;
var top = self.workspace_.latestClick.y;
......@@ -569,6 +569,9 @@ Blockly.TypeBlock.prototype.createAutoComplete_ = function(inputText){
self.workspace_.requestErrorChecking(block);
self.hide();
self.workspace_.getParentSvg().parentNode.focus(); // refocus workspace div
} finally {
Blockly.Events.setGroup(false);
}
}
);
};
......@@ -603,6 +606,7 @@ Blockly.TypeBlock.prototype.connectIfPossible = function(blockSelected, createdB
// Only attempt a connection if the input is empty
else if (!inputList[i].connection.isConnected()) {
createdBlock.previousConnection.connect(inputList[i].connection);
break;
}
} catch(e) {
//We can ignore these exceptions; they happen when connecting two blocks
......
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