Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/botPage/view/blockly/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,43 @@ while(true) {
}
/* eslint-enable */
}

// Hooks to override default Blockly behaviour
/* eslint-disable no-unused-expressions */
const originalContextMenuFn = Blockly.ContextMenu.show;
Blockly.ContextMenu.show = (e, menuOptions, rtl) => {
// Rename 'Clean up blocks'
menuOptions.some(option => {
if (option.text === Blockly.Msg.CLEAN_UP) {
option.text = translate('Rearrange vertically'); // eslint-disable-line no-param-reassign
return true;
}
return false;
}) &&
/* Remove delete all blocks, but only when 'Clean up blocks' is available (i.e. workspace)
* This allows users to still delete root blocks containing blocks
*/
menuOptions.some((option, i) => {
if (
option.text === Blockly.Msg.DELETE_BLOCK ||
option.text.replace(/[0-9]+/, '%1') === Blockly.Msg.DELETE_X_BLOCKS
) {
menuOptions.splice(i, 1);
return true;
}
return false;
});
// Open the Elev.io widget when clicking 'Help'
// eslint-disable-next-line no-underscore-dangle
if (window._elev) {
menuOptions.some(option => {
if (option.text === Blockly.Msg.HELP) {
option.callback = () => window._elev.open(); // eslint-disable-line no-param-reassign, no-underscore-dangle
return true;
}
return false;
});
}
originalContextMenuFn(e, menuOptions, rtl);
};
/* eslint-enable */