Double right click issue

HI Team,

  1. So I am building something where the nodes don’t allow right click and the links have context menu on right click. For the nodes, a short snippet would be
if (link) { context menu code }
else {
diagramRef.current.clearSelection(true);
diagramRef.current.select(selectedNode);
}

here - selectedNode is the previously selected node if any. So m not sure how to disable the right click in else block, instead I mentioned to clear the selection when right clicked and select back the previous selected node.

Could anyone suggest a better way to block the right click in case of nodes.

  1. Also, there is an event where I click control+click+click on mac, which is control+double click and its a different event than right click, if anyone knows how to handle it?

  2. I don’t want the right click or double right click to even give focus on nodes, any ideas?

Thanks,
Kanika

Normally one would not declare any contextMenu Adornment or contextClick event handler on the Node template, but would on the Link template.

You can check the InputEvent.clickCount to see if it is greater than 1.

I assume by “focus” you really mean “select”. That behavior would seem a bit unusual. Or did you mean not give keyboard focus to the diagram?

But I think you could implement that do-not-select-when-right-clicking behavior by overriding a method:

      $(go.Diagram, "myDiagramDiv",
        {
          "clickSelectingTool.canStart": function() {
            if (!this.isEnabled) return false;
            if (this.diagram.lastInput.right) return false;
            if (this.isBeyondDragSize()) return false;
            return true;
          },
          . . .
        })

HI Walter,

We have context menu on links, thus cannot get rid of all the right clicks. I do not want to select a node on the right click event over them, but the links to show context menu when right clicked.

The override of ClickSelectingTool.canStart method just prevents right clicks from selecting. It should have no impact on context menus.

Oh, it worked! Thanks for the help.