Multi successive Context Clicks behavior

There is a slight difference between the behavior of BackgroundSingleClicked and BackgroundContextClicked.

Clicking left click on the Diagram 5 multiple times will trigger :


Which is what I expect.


Doing the same test with right click will trigger the BackgroundContextClicked only once, which is weird ?!

Is there any reason for this difference between the two events ?

Here is an example where you can test it

It depends on how quickly you click. If there isn’t enough time between button clicks, on the second click you get a double-click instead of a single click. Because there are both single-click and double-click events for the primary mouse button, you can get either event.

If there is enough time, you will get consecutive/repeated context click events.
There’s no BackgroundDoubleContextClicked event, so you just get a sequence of context-click events, or you don’t get anything if it would have been a double-context-click.

However it does seem inconsistent to me that one keeps getting single-click events when it should have been a triple or quadruple primary button click, but you don’t get any events for double or triple or quadruple secondary button clicks. I suspect it’s because context clicks have predefined behavior involving context menus, and you might not want repeated invocations of context menus if there were double or triple or quadruple context clicks.

Did you have a proposal in mind?

ADDENDUM: I took a look at the source code. The basic choice is made by:

    // decide whether single-click, double-click, or context-click
    let kind = 0;
    if (e.left) {
      if (e.clickCount === 1) {
        kind = 1;
      } else if (e.clickCount === 2) {
        kind = 2;
      } else { // assume more than a double-click is just a rapid single click
        kind = 1;
    } else if (e.right) {
      if (e.clickCount === 1) {
        kind = 3;

It’s been that way since long before we released 1.0.

I am trying to compare both events to the HTML DOM events. The BackgroundSingleClicked behavior seems perfect for me. It’s up to the used method later to throttle, debounce or do whatver it wants with this event.

In the other hand, for BackgroundContextClicked it seems a little bit inconsistent especially when I compare it the DOM event contextmenu or to BackgroundSingleClicked.

Since there no BackgroundDoubleContextClicked, why you’re using the e.clickCount === 1 condition ? Isn’t it possible to fire that event whenever the background was right clicked ? I understand the difference for the left click tho, it makes sense. But at least in the e.right condition I expect either to remove the clickCount or at least to change it to e.clickCount !== 2

Changing the check to be e.clickCount !== 2 would presume that there’s something special about double-clicking when clicking the secondary/right mouse button.

No matter – here’s what you can do to get more context click events:

  $(go.Diagram, . . .,
      // override this method -- must be a regular function, not an arrow function
      "clickSelectingTool.standardMouseClick": function(navig, pred) {
        const diagram = this.diagram;
        if (!diagram) return false;
        const e = diagram.lastInput;
        if (e.right) {
        return, navig, pred);
      "BackgroundSingleClicked": e => console.log("single",,
      "BackgroundDoubleClicked": e => console.log("double",,
      "BackgroundContextClicked": e => console.log("context",,
      . . .

Yep, that’s work as expected and pretty good. Thanks for the suggestion.

Did you find the reason why you’re using e.right && e.clickCount === 1 to fire the right click event ? I am curious to know

The reason? Sorry, it’s too long ago and I don’t remember.

I just tried left click then right click, it doesn’t work either since the right click is the second one.

But, I tested this solution and it works very well.
I also used findObjectAt to locate the clicked objects.