Oh, I think I've misunderstood what you are trying to achieve.
Your scenario is impossible to implement properly (i.e. without delays), since to know if the event is click or a double-click one must know the future =)
That's why 99% of the time single-click invokes an action that is a part of a double-click action or at the very least does not contradict a double-click action. E.g. click - `Select`, dblclick - `Execute the selected item`; click - `Select the whole string`, dblclick - `Select only one word from the string`.
IMO, you should rework your scenario and remove the context menu from the click action.
Yep, was that.
I have managed to do it though, with delays...
this.lbtn_up = (x, y) => { // on_mouse_lbtn_up(x, y)
...
if (!this.bDoubleclick) { // it's not a second lbtn click
this.timeOut = this.delayedEdit(x,y, undefined, this.index);
} else {this.bDoubleclick = false;}
...
}
this.lbtn_dblclk = (x, y) => { // Called by on_mouse_lbtn_dblclk(x, y)
clearTimeout(this.timeOut);
this.timeOut = null;
this.bDoubleclick = true;
...doyourthing
}
this.edit = (x, y, menuIdx = null, forcedIndex = null) => { // use index from on_mouse_move(x, y), so you have to forceIndex from first call
...doyourthing
}
this.delayedEdit = delayFn(this.edit, 100);
this.timeOut = null;
this.bDoubleclick = false;
on helpers
const delayFn = (func, ms) => {
return (...args) => {return setTimeout(func.bind(this, ...args), ms);}
}
I have to pass the index to this.edit() because the mouse may move after clicking once and select another thing different to the original one which fired the contextual menu, but it works flawless now.