Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow splicing into shadow block stacks #6939

Merged
merged 2 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions core/connection_checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ export class ConnectionChecker implements IConnectionChecker {
}

// Don't offer to splice into a stack where the connected block is
// immovable.
if (b.targetBlock() && !b.targetBlock()!.isMovable()) {
// immovable, unless the block is a shadow block.
if (b.targetBlock() && !b.targetBlock()!.isMovable() &&
!b.targetBlock()!.isShadow()) {
return false;
}
break;
Expand Down
25 changes: 25 additions & 0 deletions tests/mocha/connection_checker_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,31 @@ suite('Connection checker', function() {
'Should connect two compatible stack blocks');
});

test('Connect to unmovable shadow block', function() {
// Remove original test blocks.
this.workspace.clear();

// Add the same test blocks, but this time block B is a shadow block.
Blockly.Xml.domToWorkspace(Blockly.utils.xml.textToDom(`<xml xmlns="https://developers.google.com/blockly/xml">
<block type="text_print" id="A" x="-76" y="-112">
<next>
<shadow type="text_print" id="B" movable="false">
</shadow>
</next>
</block>
<block type="text_print" id="C" x="47" y="-118"/>
</xml>`), this.workspace);
[this.blockA, this.blockB, this.blockC] = this.workspace.getAllBlocks(true);

// Try to connect blockC into the input connection of blockA, replacing blockB.
// This is allowed because shadow blocks can always be replaced, even though
// they are unmovable.
chai.assert.isTrue(
this.checker.doDragChecks(
this.blockC.previousConnection, this.blockA.nextConnection, 9000),
'Should connect in place of a shadow block');
});

test('Do not splice into unmovable stack', function() {
// Try to connect blockC above blockB. It shouldn't work because B is not movable
// and is already connected to A's nextConnection.
Expand Down