Skip to content

Commit 8e1890a

Browse files
maribethbBeksOmega
authored andcommitted
fix: allow splicing into shadow block stacks (#6939)
* fix: allow splicing into shadow block stacks * chore: format (cherry picked from commit 69afe5b)
1 parent 9c9aef1 commit 8e1890a

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

core/connection_checker.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,9 @@ export class ConnectionChecker implements IConnectionChecker {
250250
}
251251

252252
// Don't offer to splice into a stack where the connected block is
253-
// immovable.
254-
if (b.targetBlock() && !b.targetBlock()!.isMovable()) {
253+
// immovable, unless the block is a shadow block.
254+
if (b.targetBlock() && !b.targetBlock()!.isMovable() &&
255+
!b.targetBlock()!.isShadow()) {
255256
return false;
256257
}
257258
break;

tests/mocha/connection_checker_test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,31 @@ suite('Connection checker', function() {
367367
'Should connect two compatible stack blocks');
368368
});
369369

370+
test('Connect to unmovable shadow block', function() {
371+
// Remove original test blocks.
372+
this.workspace.clear();
373+
374+
// Add the same test blocks, but this time block B is a shadow block.
375+
Blockly.Xml.domToWorkspace(Blockly.utils.xml.textToDom(`<xml xmlns="https://developers.google.com/blockly/xml">
376+
<block type="text_print" id="A" x="-76" y="-112">
377+
<next>
378+
<shadow type="text_print" id="B" movable="false">
379+
</shadow>
380+
</next>
381+
</block>
382+
<block type="text_print" id="C" x="47" y="-118"/>
383+
</xml>`), this.workspace);
384+
[this.blockA, this.blockB, this.blockC] = this.workspace.getAllBlocks(true);
385+
386+
// Try to connect blockC into the input connection of blockA, replacing blockB.
387+
// This is allowed because shadow blocks can always be replaced, even though
388+
// they are unmovable.
389+
chai.assert.isTrue(
390+
this.checker.doDragChecks(
391+
this.blockC.previousConnection, this.blockA.nextConnection, 9000),
392+
'Should connect in place of a shadow block');
393+
});
394+
370395
test('Do not splice into unmovable stack', function() {
371396
// Try to connect blockC above blockB. It shouldn't work because B is not movable
372397
// and is already connected to A's nextConnection.

0 commit comments

Comments
 (0)