mirror of
https://github.com/google/blockly.git
synced 2026-01-07 00:50:27 +01:00
fix: Fix bug in BlockSvg.prototype.setParent (#8934)
* test(BlockSvg): Add tests for setParent(null) when dragging Add tests for scenarios where block(s) unrelated to the block being disconnected has/have been marked as as being dragged. Due to a bug in BlockSvg.prototype.setParent, one of these fails in the case that the dragging block is not a top block. Also add a check to assertNonParentAndOrphan to check that the orphan block's SVG root's parent is the workspace's canvass (i.e., that orphan is a top-level block in the DOM too). * fix(BlockSvg): Fix bug in setParent re: dragging block Fix an incorrect assumption in setParent: the topmost block whose root SVG element has the blocklyDragging class may not actually be a top-level block. * refactor(BlockDragStrategy): Hide connection preview earlier * chore(BlockDragStrategy): prefer ?. to !. Per nit on PR #8934. * fix(BlockSvg): Spelling: "canvass" -> "canvas"
This commit is contained in:
committed by
GitHub
parent
dee27b905d
commit
b9b40f48ab
@@ -1105,6 +1105,18 @@ suite('Blocks', function () {
|
||||
);
|
||||
this.textJoinBlock = this.printBlock.getInputTargetBlock('TEXT');
|
||||
this.textBlock = this.textJoinBlock.getInputTargetBlock('ADD0');
|
||||
this.extraTopBlock = Blockly.Xml.domToBlock(
|
||||
Blockly.utils.xml.textToDom(`
|
||||
<block type="text_print">
|
||||
<value name="TEXT">
|
||||
<block type="text">
|
||||
<field name="TEXT">drag me</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>`),
|
||||
this.workspace,
|
||||
);
|
||||
this.extraNestedBlock = this.extraTopBlock.getInputTargetBlock('TEXT');
|
||||
});
|
||||
|
||||
function assertBlockIsOnlyChild(parent, child, inputName) {
|
||||
@@ -1116,6 +1128,10 @@ suite('Blocks', function () {
|
||||
assert.equal(nonParent.getChildren().length, 0);
|
||||
assert.isNull(nonParent.getInputTargetBlock('TEXT'));
|
||||
assert.isNull(orphan.getParent());
|
||||
assert.equal(
|
||||
orphan.getSvgRoot().parentElement,
|
||||
orphan.workspace.getCanvas(),
|
||||
);
|
||||
}
|
||||
function assertOriginalSetup() {
|
||||
assertBlockIsOnlyChild(this.printBlock, this.textJoinBlock, 'TEXT');
|
||||
@@ -1187,6 +1203,27 @@ suite('Blocks', function () {
|
||||
);
|
||||
assertNonParentAndOrphan(this.textJoinBlock, this.textBlock, 'ADD0');
|
||||
});
|
||||
test('Setting parent to null with dragging block', function () {
|
||||
this.extraTopBlock.setDragging(true);
|
||||
this.textBlock.outputConnection.disconnect();
|
||||
assert.doesNotThrow(
|
||||
this.textBlock.setParent.bind(this.textBlock, null),
|
||||
);
|
||||
assertNonParentAndOrphan(this.textJoinBlock, this.textBlock, 'ADD0');
|
||||
assert.equal(
|
||||
this.textBlock.getSvgRoot().nextSibling,
|
||||
this.extraTopBlock.getSvgRoot(),
|
||||
);
|
||||
});
|
||||
test('Setting parent to null with non-top dragging block', function () {
|
||||
this.extraNestedBlock.setDragging(true);
|
||||
this.textBlock.outputConnection.disconnect();
|
||||
assert.doesNotThrow(
|
||||
this.textBlock.setParent.bind(this.textBlock, null),
|
||||
);
|
||||
assertNonParentAndOrphan(this.textJoinBlock, this.textBlock, 'ADD0');
|
||||
assert.equal(this.textBlock.getSvgRoot().nextSibling, null);
|
||||
});
|
||||
test('Setting parent to null without disconnecting', function () {
|
||||
assert.throws(this.textBlock.setParent.bind(this.textBlock, null));
|
||||
assertOriginalSetup.call(this);
|
||||
|
||||
Reference in New Issue
Block a user