diff --git a/src/external/bot-skeleton/scratch/hooks/workspace_svg.js b/src/external/bot-skeleton/scratch/hooks/workspace_svg.js index 9d85e6df..091ba8e7 100644 --- a/src/external/bot-skeleton/scratch/hooks/workspace_svg.js +++ b/src/external/bot-skeleton/scratch/hooks/workspace_svg.js @@ -79,20 +79,30 @@ window.Blockly.WorkspaceSvg.prototype.addBlockNode = function (block_node) { const { flyout } = DBotStore.instance; const block = window.Blockly.Xml.domToBlock(block_node, flyout.getFlyout().targetWorkspace); const top_blocks = this.getTopBlocks(true); - const new_block = flyout.getFlyout().createBlock(false, block); + + if (config().single_instance_blocks.includes(block.type)) { + this.getAllBlocks().forEach(ws_block => { + if (ws_block.type === block.type && ws_block.id !== block.id) { + ws_block.dispose(); + } + }); + } if (top_blocks.length) { const last_block = top_blocks[top_blocks.length - 1]; const last_block_xy = last_block.getRelativeToSurfaceXY(); const extra_spacing = last_block.startHat_ ? window.Blockly.BlockSvg.START_HAT_HEIGHT : 0; const y = last_block_xy.y + last_block.getHeightWidth().height + extra_spacing + 30; - new_block.moveBy(last_block_xy.x, y); + block.moveBy(last_block_xy.x, y); } + flyout.setIsSearchFlyout(false); + flyout.setVisibility(false); + // Call svgResize to avoid glitching workspace. - window.Blockly.svgResize(new_block.workspace); + window.Blockly.svgResize(block.workspace); // kept this commented since it is making a glitching issue, - //this.centerOnBlock(new_block.id, false); + // this.centerOnBlock(new_block.id, false); }; /**