Fix undoing function argument changes.

This commit is contained in:
Neil Fraser
2016-03-24 15:30:29 -07:00
parent 39fbd24659
commit e0ebce1b60
4 changed files with 15 additions and 6 deletions

View File

@@ -504,10 +504,16 @@ Blockly.Blocks['procedures_callnoreturn'] = {
// Existing param IDs.
// Note that quarkConnections_ may include IDs that no longer exist, but
// which might reappear if a param is reattached in the mutator.
if (!paramIds) {
// Reset the quarks (a mutator is about to open).
var defBlock = Blockly.Procedures.getDefinition(this.getProcedureCall(),
this.workspace);
var mutatorOpen = defBlock && defBlock.mutator &&
defBlock.mutator.isVisible();
if (!mutatorOpen) {
this.quarkConnections_ = {};
this.quarkIds_ = null;
}
if (!paramIds) {
// Reset the quarks (a mutator is about to open).
return;
}
if (goog.array.equals(this.arguments_, paramNames)) {
@@ -539,7 +545,8 @@ Blockly.Blocks['procedures_callnoreturn'] = {
if (input) {
var connection = input.connection.targetConnection;
this.quarkConnections_[this.quarkIds_[i]] = connection;
if (connection && paramIds.indexOf(this.quarkIds_[i]) == -1) {
if (mutatorOpen && connection &&
paramIds.indexOf(this.quarkIds_[i]) == -1) {
// This connection should no longer be attached to this block.
connection.disconnect();
connection.getSourceBlock().bumpNeighbours_();

View File

@@ -331,7 +331,8 @@ Blockly.Connection.prototype.checkConnection_ = function(target) {
case Blockly.Connection.REASON_SELF_CONNECTION:
throw 'Attempted to connect a block to itself.';
case Blockly.Connection.REASON_DIFFERENT_WORKSPACES:
throw 'Blocks are on different workspaces.';
// Usually this means one block has been deleted.
throw 'Blocks not on same workspace.';
case Blockly.Connection.REASON_WRONG_TYPE:
throw 'Attempt to connect incompatible types.';
case Blockly.Connection.REASON_TARGET_NULL:

View File

@@ -423,6 +423,7 @@ Blockly.Events.Change.prototype.run = function(forward) {
oldMutation = oldMutationDom && Blockly.Xml.domToText(oldMutationDom);
}
if (block.domToMutation) {
value = value || '<mutation></mutation>';
var dom = Blockly.Xml.textToDom('<xml>' + value + '</xml>');
block.domToMutation(dom.firstChild);
}

View File

@@ -349,8 +349,8 @@ Blockly.Mutator.prototype.dispose = function() {
* @return {boolean} True iff a reconnection was made, false otherwise.
*/
Blockly.Mutator.reconnect = function(connectionChild, block, inputName) {
if (!connectionChild) {
return false;
if (!connectionChild || !connectionChild.getSourceBlock().workspace) {
return false; // No connection or block has been deleted.
}
var connectionParent = block.getInput(inputName).connection;
var currentParent = connectionChild.targetBlock();