Add error callback to the cross tab copy paste plugin
Category
- Plugins
Component
cross-tab-copy-paste
Is your feature request related to a problem? Please describe.
There is the possibility that two unrelated projects could both have the cross tab copy paste plugin installed. This would allow people to try to paste blocks into a workspace where the definitions for those blocks do not exist (causing an error). External developers may want to handle those errors (e.g. presenting a message to the user when they happen). But currently this is not possible because there is no where for external developers to wrap the input event listeners in a try... catch.
Describe the solution you'd like
External developers should be able to pass a callback to the cross-tab-copy-paste plugin that is called when the plugin triggers an error when pasting.
Describe alternatives you've considered
N/A
Additional context
N/A
This issue has a few steps to resolve:
- Reproduce the error using the steps outlined in the "To Reproduce" section below. Once you can reproduce the bad behavior, you can test if your changes fixed it.
- Modify the code in plugins/cross-tab-copy-paste/src/index.js so that the
CrossTabCopyPasteclass accepts a callback as a parameter to itsinitfunction. - Wrap any calls to
workspace.paste()in atry...catchwhich checks for aTypeErrorand calls thecallbackif so (otherwise throws). - In plugins/cross-tab-copy-paste/test/index.js pass a callback to the
initfunction. E.g:
copyPastePlugin.init({}, () => console.log('callback called'));
- Run the reproduction steps again, and verify that your callback is properly called. I.e. you get a 'callback called' message in the browser console.
After your PR is accepted, a Blockly team member will have to publish the GitHub Pages site, and then you'll be able to see your change live!
To Reproduce
- Open up the plugins/cross-tab-copy-paste/test/index.js file.
- Add the following code snippet below the
importstatements, but above thecreateWorkspacefunction:
Blockly.Blocks['test'] = {
init: function() {
this.appendDummyInput('test').appendField('test');
},
};
- Run
npm run startfrom thecross-tab-copy-pastedirectory. - Paste the following JSON into the 'JSON' tab on the right of the resulting webpage:
{
"blocks": {
"languageVersion": 0,
"blocks": [
{
"type": "test",
"x": 10,
"y": 10
}
]
}
}
- Right click the pasted JSON and select the "Import from JSON" option.
- Right click the resulting block, and select the "Copy" option.
- Comment out the block definition from step 2.
- Wait for the page to reload.
- Right click the workspace, and select the "Paste" option.
- Open the console and observe the error.
@BeksOmega since this is open and none of the OSD participants picked it up, maybe I can work on this!
@BeksOmega since this is open and none of the OSD participants picked it up, maybe I can work on this!
Just assigned you! That would be awesome : )