diff --git a/core/events.js b/core/events.js index 2d0ae0b1b..2a00f205a 100644 --- a/core/events.js +++ b/core/events.js @@ -95,7 +95,7 @@ Blockly.Events.fireNow_ = function() { for (var i = 0, detail; detail = queue[i]; i++) { console.log(detail); var workspace = Blockly.Workspace.getById(detail.workspaceId); - if (workspace.rendered) { + if (workspace && workspace.rendered) { // Create a custom event in a browser-compatible way. if (typeof CustomEvent == 'function') { // W3 @@ -124,11 +124,21 @@ Blockly.Events.filter_ = function(queueIn) { if (event1.type == Blockly.Events.MOVE && event2.type == Blockly.Events.MOVE && event1.blockId == event2.blockId) { + // Merge move events. event1.newParentId = event2.newParentId; event1.newInputName = event2.newInputName; event1.newCoordinate = event2.newCoordinate; queue.splice(j, 1); j--; + } else if (event1.type == Blockly.Events.CHANGE && + event2.type == Blockly.Events.CHANGE && + event1.blockId == event2.blockId && + event1.element == event2.element && + event1.name == event2.name) { + // Merge change events. + event1.newValue = event2.newValue; + queue.splice(j, 1); + j--; } } } diff --git a/core/mutator.js b/core/mutator.js index 430b58af0..5f51f97bf 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -283,6 +283,7 @@ Blockly.Mutator.prototype.workspaceChanged_ = function() { // When the mutator's workspace changes, update the source block. if (this.rootBlock_.workspace == this.workspace_) { + var oldMutation = this.block_.mutationToDom(); // Switch off rendering while the source block is rebuilt. var savedRendered = this.block_.rendered; this.block_.rendered = false; @@ -292,12 +293,18 @@ Blockly.Mutator.prototype.workspaceChanged_ = function() { this.block_.rendered = savedRendered; // Mutation may have added some elements that need initalizing. this.block_.initSvg(); + var newMutation = this.block_.mutationToDom(); + if (Blockly.Xml.domToText(oldMutation) != + Blockly.Xml.domToText(newMutation)) { + Blockly.Events.fire(new Blockly.Events.Change( + this.block_, 'mutation', null, oldMutation, newMutation)); + goog.Timer.callOnce( + this.block_.bumpNeighbours_, Blockly.BUMP_DELAY, this.block_); + } if (this.block_.rendered) { this.block_.render(); } this.resizeBubble_(); - goog.Timer.callOnce( - this.block_.bumpNeighbours_, Blockly.BUMP_DELAY, this.block_); } };