Thank you both for sharing your input! I tried Christophers suggestion but I'm having a problem with the undo/redo. After I create block A and end it's the drag I was expecting that the undo would move block A to the position of block B and the 2nd undo would destroy it, but block A moves first to the top of the screen before the deletion. Something like:
drag start block B > create block A > stop dragging block A > undo (move block A to block B) > undo (move block A to top-left corner of the workspace) > undo (delete block A)
The code is as follows:
import * as Blockly from 'blockly/core';
export default class ArgumentDragStrategy extends Blockly.dragging
.BlockDragStrategy {
public targetWorkspace;
public targetBlock: Blockly.BlockSvg | null;
constructor(block: Blockly.BlockSvg) {
super(block);
this.targetBlock = null;
this.targetWorkspace = block.workspace;
}
startDrag(e?: PointerEvent): void {
this.targetBlock = this.targetWorkspace.newBlock('Number');
this.targetBlock.initSvg();
this.targetBlock.render();
this.targetBlock.startDrag(e);
}
drag(newLoc: Blockly.utils.Coordinate): void {
this.targetBlock?.drag(newLoc);
}
endDrag(e: PointerEvent) {
this.targetBlock?.endDrag(e);
}
}
I've also tried pasting block A directly at the position of block B, disabling events (which causes other problems) and I still have the same problem. Does anyone have any suggestions?