From 4ae34599e032b7bf03b991d70003043771738b1c Mon Sep 17 00:00:00 2001 From: rachel-fenichel Date: Fri, 11 Mar 2016 17:38:59 -0800 Subject: [PATCH] Don't connect a block with no next connection if that would force a bump. --- core/connection.js | 8 ++++++++ tests/jsunit/connection_test.js | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/core/connection.js b/core/connection.js index 4db07585f..1e38fe42c 100644 --- a/core/connection.js +++ b/core/connection.js @@ -373,6 +373,14 @@ Blockly.Connection.prototype.isConnectionAllowed = function(candidate, return false; } + // Don't let a block with no next connection bump other blocks out of the + // stack. + if (this.type == Blockly.PREVIOUS_STATEMENT && + candidate.targetConnection && + !this.sourceBlock_.nextConnection) { + return false; + } + // Don't let blocks try to connect to themselves or ones they nest. var targetSourceBlock = candidate.sourceBlock_; var sourceBlock = this.sourceBlock_; diff --git a/tests/jsunit/connection_test.js b/tests/jsunit/connection_test.js index e0b91efee..c9ad00dae 100644 --- a/tests/jsunit/connection_test.js +++ b/tests/jsunit/connection_test.js @@ -279,6 +279,25 @@ function test_isConnectionAllowed() { assertFalse(one.isConnectionAllowed(two, 1000.0)); } +function test_isConnectionAllowed_NoNext() { + var sharedWorkspace = {}; + var one = helper_createConnection(0, 0, Blockly.NEXT_STATEMENT); + one.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace); + one.sourceBlock_.nextConnection = one; + + var two = helper_createConnection(0, 0, Blockly.PREVIOUS_STATEMENT); + two.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace); + + assertTrue(two.isConnectionAllowed(one, 1000.0)); + + var three = helper_createConnection(0, 0, Blockly.PREVIOUS_STATEMENT); + three.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace); + three.sourceBlock_.previousConnection = three; + Blockly.Connection.connectReciprocally_(one, three); + + assertFalse(two.isConnectionAllowed(one, 1000.0)); +} + function testCheckConnection_Okay() { connectionTest_setUp(); previous.checkConnection_(next);