diff --git a/blocks/logic.js b/blocks/logic.js
index 26e4e3f47..6b789db0a 100644
--- a/blocks/logic.js
+++ b/blocks/logic.js
@@ -520,8 +520,6 @@ Blockly.Constants.Logic.fixLogicCompareRtlOpLabels =
* @readonly
*/
Blockly.Constants.Logic.LOGIC_COMPARE_ONCHANGE_MIXIN = {
- prevBlocks_: [null, null],
-
/**
* Called whenever anything on the workspace changes.
* Prevent mismatched types from being compared.
@@ -529,25 +527,37 @@ Blockly.Constants.Logic.LOGIC_COMPARE_ONCHANGE_MIXIN = {
* @this Blockly.Block
*/
onchange: function(e) {
+ if (!this.prevBlocks_) {
+ this.prevBlocks_ = [null, null];
+ }
+
var blockA = this.getInputTargetBlock('A');
var blockB = this.getInputTargetBlock('B');
// Disconnect blocks that existed prior to this change if they don't match.
if (blockA && blockB &&
!blockA.outputConnection.checkType_(blockB.outputConnection)) {
- // Mismatch between two inputs. Disconnect previous and bump it away.
- // Ensure that any disconnections are grouped with the causing event.
+ // Mismatch between two inputs. Revert the block connections,
+ // bumping away the newly connected block(s).
Blockly.Events.setGroup(e.group);
- for (var i = 0; i < this.prevBlocks_.length; i++) {
- var block = this.prevBlocks_[i];
- if (block === blockA || block === blockB) {
- block.unplug();
- block.bumpNeighbours_();
+ var prevA = this.prevBlocks_[0];
+ if (prevA !== blockA) {
+ blockA.unplug();
+ if (prevA) {
+ this.getInput('A').connection.connect(prevA.outputConnection);
}
}
+ var prevB = this.prevBlocks_[1];
+ if (prevB !== blockB) {
+ blockB.unplug();
+ if (prevB) {
+ this.getInput('B').connection.connect(prevB.outputConnection);
+ }
+ }
+ this.bumpNeighbours_();
Blockly.Events.setGroup(false);
}
- this.prevBlocks_[0] = blockA;
- this.prevBlocks_[1] = blockB;
+ this.prevBlocks_[0] = this.getInputTargetBlock('A');
+ this.prevBlocks_[1] = this.getInputTargetBlock('B');
}
};
diff --git a/tests/playground.html b/tests/playground.html
index a00de41e8..c91703281 100644
--- a/tests/playground.html
+++ b/tests/playground.html
@@ -1143,6 +1143,33 @@ h1 {
+
+
+
+
+
+ 10
+
+
+
+
+ 10
+
+
+
+
+
+
+ 10
+
+
+
+
+ 10
+
+
+
+