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) {
console.log(e.clickCount);
}
return go.ToolManager.prototype.standardMouseClick.call(this, navig, pred);
},
"BackgroundSingleClicked": e => console.log("single", Date.now()),
"BackgroundDoubleClicked": e => console.log("double", Date.now()),
"BackgroundContextClicked": e => console.log("context", Date.now()),
. . .