Skip to content

Commit

Permalink
Ensure dragging block to sprite creates only one. Fixes #1087 (#1088)
Browse files Browse the repository at this point in the history
  • Loading branch information
brollb authored Sep 16, 2020
1 parent 8e28303 commit a8af5b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand All @@ -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
Expand All @@ -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) {
Expand Down
19 changes: 19 additions & 0 deletions test/blocks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit a8af5b1

Please sign in to comment.