I see. Both the isolated code and video repro are very helpful. If I am understanding correctly (I probably should have clarified this earlier), your goal here is ultimately to stop the blocks moving? You mention that being bad UX--I'm not 100% sure I agree with that, but I suppose that's a different discussion from trying to reach your actual goal.
What you're seeing isn't actually the blocks moving but, rather, the 'camera'/'viewport' within the Blockly workspace (though it's not actually represented using these terms). How the view position needs to change depends largely on the workspace, and I suspect it's ultimately tied to the resize functionality. Observation suggests that attempting to resize the workspace includes some additional logic to make sure that:
- If a block is under the toolbox then the view should be shifted over so that it isn't.
- If a wide block is slightly off screen then shift so that it isn't.
This experiment can actually be tested interestingly in a few ways:
- Only changing toolbox visibility doesn't move blocks at all (which is ultimately your goal, but you may have other reasons why the workspace resize is needed). You can hide the toolbox, move a block under it, show it, observe the block hasn't moved, call 'Blockly.svgResize', then observe the block has moved.
- Try your same repro steps but put a copy of the large block on each side of the screen and then use your function. Notice that the blocks barely (if at all) move because both side constraints are trying to apply at the same time and they can't be resolved since shifting to make one side of the screen better makes the other worse.
Here's why this is tricky: resizing the workspace ensures that the workspace now knows the space underneath the toolbox can be used. If you only hide the toolbox then you may observe that the workspace won't let you drag anything underneath it. This is ultimately the way core Blockly is designed to behave. The reason why the resize logic is ultimately what causes this to happen is because that's when the toolbox's width and height are recalculated which, in turn, affect how the view metrics for an item like a block are calculated:
Simply put, the workspace treats the non-toolbox region as the place where blocks are allowed to go while on screen. Removing the toolbox and resizing the workspace provides a larger area for blocks to be, and re-adding the toolbox causes that area to shrink. Blockly then shifts the blocks to ensure they stay on screen because it makes an effort to try and ensure that the workspace origin (0, 0) is never under the toolbox. The reason for this apparently dates all the way back to the very first import of Blockly into Git, so its original reasoning may well be lost to time. :)
I suspect you ultimately don't actually care about how the machinery works. What you're really interested in is stopping the view adjustment to get blocks back on the screen without ignoring the toolbox's impacts on workspace size. Since this is largely an opinionated perspective I don't think it constitutes an actual issue in core Blockly, but it's perhaps a reasonable thing to want to be able to do. To see how that works we need to dig a bit into what can lead to scrolling:
In fact, this is exactly the line that, when commented out, fixes your problem:
I hope this helps.
Ben