Skip to content

Commit a4d97c2

Browse files
authored
fix: collapsed warning propagation across siblings (#9566) (#9567)
1 parent c79273a commit a4d97c2

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

core/block_svg.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -539,12 +539,22 @@ export class BlockSvg
539539
* @returns true if any child has a warning, false otherwise.
540540
*/
541541
private childHasWarning(): boolean {
542-
const children = this.getChildren(false);
543-
for (const child of children) {
544-
if (child.getIcon(WarningIcon.TYPE) || child.childHasWarning()) {
542+
const next = this.getNextBlock();
543+
const excluded = next ? new Set(next.getDescendants(false)) : null;
544+
const descendants = this.getDescendants(false);
545+
546+
for (const descendant of descendants) {
547+
if (descendant === this) {
548+
continue;
549+
}
550+
if (excluded?.has(descendant)) {
551+
continue;
552+
}
553+
if (descendant.getIcon(WarningIcon.TYPE)) {
545554
return true;
546555
}
547556
}
557+
548558
return false;
549559
}
550560

tests/mocha/block_test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,6 +1950,23 @@ suite('Blocks', function () {
19501950
'Warning should be removed from parent after expanding',
19511951
);
19521952
});
1953+
1954+
test('Collapsing a block should not inherit warnings from following siblings', function () {
1955+
const nextBlock = createRenderedBlock(
1956+
this.workspace,
1957+
'statement_block',
1958+
);
1959+
this.childBlock.nextConnection.connect(nextBlock.previousConnection);
1960+
nextBlock.setWarningText('Warning Text');
1961+
1962+
this.childBlock.setCollapsed(true);
1963+
1964+
const icon = this.childBlock.getIcon(Blockly.icons.WarningIcon.TYPE);
1965+
assert.isUndefined(
1966+
icon,
1967+
'Collapsed block should not show warnings from following siblings',
1968+
);
1969+
});
19531970
});
19541971

19551972
suite('Bubbles and collapsing', function () {

0 commit comments

Comments
 (0)