Don't connect a block with no next connection if that would force a bump.

This commit is contained in:
rachel-fenichel 2016-03-11 17:38:59 -08:00
parent 06ff90bcaf
commit 4ae34599e0
2 changed files with 27 additions and 0 deletions

View file

@ -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_;

View file

@ -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);