Closed ewpatton closed 6 months ago
Drag and drop multiple blocks to the backpack is already supported. I found one bug and it should be fixed in #38. Apart from that, it should work without any errors.
For the "Copy to Backpack" context menu, I don't think we can do anything here in the multi-select library to make it support multi-copy, as we have no control of the context menu item added by other plugins (the register/de-register can happen at any time in a completely different order). Instead, the adaptation should be done at the client side via the blockSelectionWeakMap
API (https://github.com/mit-cml/workspace-multiselect?tab=readme-ov-file#api) (just let "Copy to Backpack" apply to all the other selected blocks beside the Blockly-core selected one)
We could make a recommendation in the README that people who want to use both should apply the Backpack first and then the multiselect workspace and then if the context menu items for the backpack are registered we update them to be multiselect compatible.
If the context menu items for the backpack are registered we update them to be multiselect compatible.
How are we gonna make this work? We need to call the APIs in the backpack plugin to make everything applied to other blocks and I don't think making this plugin depend on the backpack plugin is a good idea.
I imagine the multiselect plugin could accept an instance of the backpack plugin as an argument:
let backpack = new Backpack(workspace);
backpack.init();
let multiselect = new Multiselect(workspace, {
useBackpack: backpack
});
and at that point we know 1) that the application is using the backpack, 2) we can override the existing backpack context menu items with our own, and 3) that we have a reference to the backpack plugin instance for a given workspace, which gives us the APIs to call to interact with it.
Obviously if folks initialize things the other way round then they wouldn't have the backpack instance to feed to multiselect, so we cannot assume anything. But of course if they want to use both then they have the option if the plugins are initialized in the correct order (which we can document).
Managed to make "Copy to backpack" multi-select compatible silently without the need for any additional steps from client developers. The backpack plugin and multi-select plugin can still be initialized in random order. This is now ready in #38
With the next iteration of the block workspace we may switch to the Blockly-provided backpack plugin. If multiple blocks are selected, we probably want our own menu substitution that copies the N selected blocks to the backpack.