blockly-samples
blockly-samples copied to clipboard
continuous-toolbox not created function
Describe the bug
https://google.github.io/blockly-samples/plugins/continuous-toolbox/test/
No created ‘abcd’ block. Expected behavior created abcd block
Screenshots

Confirming, there's a failure to refresh the toolbox after a new function definition is created. Interesting to note that if a variable is created, the toolbox does refresh, and the missing function call appears at that time.
Interesting to note that if a variable is created, the toolbox does refresh, and the missing function call appears at that time.
I think creating a variable triggers a "manual" refresh, while creating a procedure does not. My guess is that this is because clicking on the flyout button to create a variable leaves the flyout open, but dragging a procedure block out closes it. The new procedures normally show up when you open the category again, but that isn't happening in this case.
So...... how to solve it?
I have use continuous-toolbox,Is there a simple solution?
I have use continuous-toolbox,Is there a simple solution?
There is no great solution at the moment. I did come up with a work-around that uses the events system:
myWorkspace.addChangeListener((e) => {
if (e.type == Blockly.Events.BLOCK_CREATE
|| e.type == Blockly.Events.BLOCK_DELETE
|| e.type == Blockly.Events.BLOCK_MOVE) {
myWorkspace.getToolbox().refreshSelection();
}
});
But it is laggy and when you drag procedures from the toolbox it temporarily shows bad callers blocks (probably because we're not accounting for insertion markers). Sadly this needs a real fix with dev time dedicated to it :/
If you do go with this temporary solution, make sure to add this listener before deserializing any saved state! Eg before Blockly.Xml.domToWorkspace.
To test this in the demo you can open the console and add the following code:
Blockly.mainWorkspace.addChangeListener((e) => {
if (e.type == Blockly.Events.BLOCK_CREATE
|| e.type == Blockly.Events.BLOCK_DELETE
|| e.type == Blockly.Events.BLOCK_MOVE) {
Blockly.mainWorkspace.getToolbox().refreshSelection();
}
});
I hope that work-around works for you temporarily!
Is there a better way now?Has this bug been fixed?
I added the change listener fix as a temporary solution. If we ever get procedure-specific events, the change listener should be modified to use those instead.
Ok, the change listener I implemented kind of worked. Callers are being added to the toolbox when defs are created, but when the procedure defs are mutated the callers in the toolbox are not updated to match.