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