Skip to content

Commit

Permalink
Merge pull request #123 from farabi-deriv/farabi/bot-2324/blocks-gett…
Browse files Browse the repository at this point in the history
…ing-duplicated-on-clicking-add

Farabi/bot-2324/blocks-getting-duplicated-on-clicking-add
  • Loading branch information
sandeep-deriv authored Nov 20, 2024
2 parents f13c83f + 8a9342b commit f3d2e30
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/external/bot-skeleton/scratch/hooks/workspace_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
Expand Down

0 comments on commit f3d2e30

Please sign in to comment.