From 82f1ab1157b393189849fae0e629073db454aac0 Mon Sep 17 00:00:00 2001 From: Paul Kendall Date: Tue, 3 Feb 2015 11:06:57 +1300 Subject: [PATCH] Fix the logic block to bump the correct block. Previously it was always bumping the first block added even if you are putting the new block over the first block, so it bumped the new block as well. --- blocks/logic.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/blocks/logic.js b/blocks/logic.js index 4ae0f80c0..5a66ae2d5 100644 --- a/blocks/logic.js +++ b/blocks/logic.js @@ -312,19 +312,18 @@ Blockly.Blocks['logic_compare'] = { } var blockA = this.getInputTargetBlock('A'); var blockB = this.getInputTargetBlock('B'); - // Keep track of which block was added second - // (so the first block may be ejected upon mismatch). - if (blockA && !blockB) { - this.blockAPriority_ = false; - } else if (!blockA && blockB) { - this.blockAPriority_ = true; - } else if (blockA && blockB && - !blockA.outputConnection.checkType_(blockB.outputConnection)) { - // Mismatch between two inputs. Disconnect one and bump it away. - var child = this.blockAPriority_ ? blockB : blockA; - child.setParent(null); - child.bumpNeighbours_(); + // Kick blocks that existed prior to this change if they don't match + if (this.blocks_ && blockA && blockB && + !blockA.outputConnection.checkType_(blockB.outputConnection)) { + // Mismatch between two inputs. Disconnect previous and bump it away. + goog.array.forEach(this.blocks_, function(e) { + if (e === blockA || e === blockB) { + e.setParent(null); + e.bumpNeighbours_(); + } + }); } + this.blocks_ = [blockA, blockB]; } };