diff --git a/src/gui.js b/src/gui.js index a2b963575b..90cf2a7b19 100644 --- a/src/gui.js +++ b/src/gui.js @@ -8757,9 +8757,9 @@ SpriteIconMorph.prototype.reactToDropOf = function (morph, hand) { morph.slideBackTo(hand.grabOrigin); }; -SpriteIconMorph.prototype.copyStack = function (block) { +SpriteIconMorph.prototype.copyStack = async function (block) { var sprite = this.object, - dup = block.fullCopy(), + dup = block.id ? block.fullCopy() : block, // FIXME: This positioning can be problematic... y = Math.max( sprite.scripts.children.map(stack => @@ -8768,10 +8768,7 @@ SpriteIconMorph.prototype.copyStack = function (block) { ), position = new Point(this.object.scripts.left() + 20, y + 20); - dup.setPosition(position); - sprite.scripts.add(dup); dup.allComments().forEach(comment => comment.align(dup)); - sprite.scripts.adjustBounds(); // delete all local custom blocks (methods) that the receiver // doesn't understand @@ -8785,7 +8782,8 @@ SpriteIconMorph.prototype.copyStack = function (block) { }); dup.id = null; - SnapActions.addBlock(dup, sprite, position); + await SnapActions.addBlock(dup, sprite, position); + sprite.scripts.adjustBounds(); }; SpriteIconMorph.prototype.copyCostume = function (costume) { diff --git a/test/blocks.spec.js b/test/blocks.spec.js index 25761eba33..bf795acdc7 100644 --- a/test/blocks.spec.js +++ b/test/blocks.spec.js @@ -480,6 +480,25 @@ describe('blocks', function() { }); }); + describe('across sprites', function() { + beforeEach(() => driver.reset()); + + it('should add new block on sprite icon drop', async function() { + const {BlockMorph} = driver.globals(); + const block = driver.palette().contents.children + .find(c => c instanceof BlockMorph); + const [spriteIcon] = driver.ide().corral.frame.contents.children; + driver.dragAndDrop(block, spriteIcon.center(), block.center()); + await driver.actionsSettled(); + const sprite = driver.ide().currentSprite; + assert.equal( + sprite.scripts.children.length, + 1, + 'Created multiple blocks in sprite' + ); + }); + }); + describe('moveBlock', function() { before(() => driver.reset());