Skip to content

Commit

Permalink
feat: hook to "_Blockly.getMainWorkspace().showContextMenu" instead o…
Browse files Browse the repository at this point in the history
…f "_Blockly.ContextMenu.show"; LennardF1989#28
  • Loading branch information
MagneticNeedle committed Apr 25, 2023
1 parent 74295af commit a39cd72
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,6 @@ BF2042Portal.Extensions = (function () {
hookBlockDefinitions();
hookContextMenu();
hookWorkspaceSvg();

initializeDocumentEvents();
intializeBlockly();

Expand Down Expand Up @@ -1190,18 +1189,21 @@ BF2042Portal.Extensions = (function () {
}

function hookContextMenu() {
const originalShow = _Blockly.ContextMenu.show;

_Blockly.ContextMenu.show = (e, options, rtl) => {
if(!_Blockly.getMainWorkspace()){
setTimeout(hookContextMenu, 100);
return;
}
const originalShow = _Blockly.getMainWorkspace().showContextMenu
_Blockly.getMainWorkspace().showContextMenu = function (e) {
lastContextMenu = {
e,
options,
rtl
e: e,
options: _Blockly.ContextMenuRegistry.registry.getContextMenuOptions(
_Blockly.ContextMenuRegistry.ScopeType.WORKSPACE, {workspace: _Blockly.getMainWorkspace()}
),
rtl: _Blockly.getMainWorkspace().RTL
};

updateMouseCoords(lastContextMenu.e);

return originalShow(e, options, rtl);
updateMouseCoords(e);
return originalShow.apply(this, arguments);
}
}

Expand Down Expand Up @@ -1500,7 +1502,6 @@ BF2042Portal.Extensions = (function () {
let activeBlock;

const workspace = _Blockly.getMainWorkspace();

workspace.addChangeListener(function (e) {
if (e.type === _Blockly.Events.CLICK || e.type === _Blockly.Events.SELECTED) {
if (shiftKey) {
Expand Down Expand Up @@ -1564,7 +1565,7 @@ BF2042Portal.Extensions = (function () {
}

// Gets the x and y position of the cursor relative to the workspace's parent svg element.
const mouseXY = _Blockly.utils.mouseToSvg(
const mouseXY = _Blockly.browserEvents.mouseToSvg(
event,
mainWorkspace.getParentSvg(),
mainWorkspace.getInverseScreenCTM()
Expand Down

0 comments on commit a39cd72

Please sign in to comment.