blockly-samples icon indicating copy to clipboard operation
blockly-samples copied to clipboard

continuous-toolbox not created function

Open YangJiawei opened this issue 4 years ago • 8 comments

Describe the bug

https://google.github.io/blockly-samples/plugins/continuous-toolbox/test/

No created ‘abcd’ block. Expected behavior created abcd block

Screenshots 20210802181607

YangJiawei avatar Aug 02 '21 10:08 YangJiawei

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.

NeilFraser avatar Aug 03 '21 10:08 NeilFraser

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.

BeksOmega avatar Aug 03 '21 13:08 BeksOmega

So...... how to solve it?

YangJiawei avatar Aug 12 '21 05:08 YangJiawei

I have use continuous-toolbox,Is there a simple solution?

YangJiawei avatar Aug 12 '21 05:08 YangJiawei

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!

BeksOmega avatar Aug 12 '21 14:08 BeksOmega

Is there a better way now?Has this bug been fixed?

YangJiawei avatar Sep 25 '21 09:09 YangJiawei

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.

BeksOmega avatar Jul 15 '22 18:07 BeksOmega

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.

BeksOmega avatar Dec 12 '22 22:12 BeksOmega