mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-28 22:10:31 -04:00
Don't connect a block with no next connection if that would force a bump.
This commit is contained in:
parent
06ff90bcaf
commit
4ae34599e0
2 changed files with 27 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue