diff --git a/src/blocks.js b/src/blocks.js index 68a6333e48..bd9130bfe7 100644 --- a/src/blocks.js +++ b/src/blocks.js @@ -7614,7 +7614,9 @@ ScriptsMorph.prototype.moveBlock = function (block, target, hand) { }; ScriptsMorph.prototype.addBlock = function (block) { - SnapActions.addBlock(block, this.scriptTarget(), block.position()); + const target = this.parentThatIsA(BlockEditorMorph) || + this.scriptTarget(); + SnapActions.addBlock(block, target, block.position()); block.destroy(); }; diff --git a/test/blocks.spec.js b/test/blocks.spec.js index bf795acdc7..25351208ac 100644 --- a/test/blocks.spec.js +++ b/test/blocks.spec.js @@ -418,6 +418,40 @@ describe('blocks', function() { ); }); + it('should add new block to block editor', async () => { + const {BlockEditorMorph} = driver.globals(); + const sprite = driver.ide().currentSprite; + const spec = 'sprite block %s'; + const definition = new CustomBlockDefinition(spec, sprite); + + // Get the sprite + definition.category = 'motion'; + await SnapActions.addCustomBlock(definition, sprite); + + // Edit the custom block + driver.selectCategory('custom'); + const customBlock = driver.palette().contents.children + .find(item => item instanceof CustomCommandBlockMorph); + driver.rightClick(customBlock); + let editBtn = driver.dialog().children.find(item => item.action === 'edit'); + driver.click(editBtn); + + const editor = driver.dialog(); + const scripts = editor.body.contents; + + driver.selectCategory('motion'); + const positionBlock = driver.palette().contents.children + .find(item => item.selector === 'xPosition'); + + driver.dragAndDrop(positionBlock, scripts.center()); + await driver.actionsSettled(); + const block = Object.values(SnapActions._blocks)[0]; + assert( + block.parentThatIsA(BlockEditorMorph), + 'Expected position block to be in block editor' + ); + }); + it('should be able to change type from dialog', async () => { var sprite = driver.ide().currentSprite, spec = 'sprite block %s',