Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure dragging block to sprite creates only one. Fixes #1087 #1088

Merged
merged 1 commit into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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