Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The lastContextMenu is not initialized leading to a crash when a item in ContextMenu is clicked on #28

Closed
Tracked by #27
p0lygun opened this issue Apr 25, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@p0lygun
Copy link

p0lygun commented Apr 25, 2023

as discussed in #27 , after v9 the context menu is imported and hence not accessible to hookup directly, instead of using that we can hook _Blockly.getMainWorkspace().showContextMenu as that calls to ContextMenu.show() in the end

I am able to fix the crash by doing this

    function hookContextMenu() {
        if(!_Blockly.getMainWorkspace()){
            setTimeout(hookContextMenu, 100);
            return;
        }
        const originalShow = _Blockly.getMainWorkspace().showContextMenu
        _Blockly.getMainWorkspace().showContextMenu = function (e) {
            lastContextMenu = {
                e: e,
                options: _Blockly.ContextMenuRegistry.registry.getContextMenuOptions(
                    _Blockly.ContextMenuRegistry.ScopeType.WORKSPACE, {workspace: _Blockly.getMainWorkspace()}
                ),
                rtl: _Blockly.getMainWorkspace().RTL
            };
            updateMouseCoords(e);
            return originalShow.apply(this, arguments);
        }
    }
p0lygun pushed a commit to p0lygun/BF2042-Portal-Extensions that referenced this issue Apr 25, 2023
p0lygun pushed a commit to p0lygun/BF2042-Portal-Extensions that referenced this issue Apr 25, 2023
@LennardF1989 LennardF1989 added the bug Something isn't working label May 1, 2023
@LennardF1989
Copy link
Owner

Closing this as it's tracked by #27 and should be fixed with 2.0.0-pr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants