mirror of
https://github.com/google/blockly.git
synced 2026-01-09 01:50:11 +01:00
Don't connect a block with no next connection if that would force a bump.
This commit is contained in:
@@ -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_;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user