We have a scenario where we start a drag programmatically and let the user finish it with a mouse click in the desired location. This works in Babylon 5.5.5, but not in latest.
It looks like this broke as a side-effect of Fix PointerDragBehavior to account for button context, add button filter · Pull Request 12499. When a drag is started programmatically, _activeDragButton
remains -1, so the condition in the pointer-up handler will never be satisfied, and thus the drag can’t end with a click. (And the pointer-down event beforehand doesn’t help, since it doesn’t do anything if you’re already dragging.)
I have a couple of ideas for a fix, but I’m not sure which one is preferable:
- In the pointer-down handler, if we’re already dragging but don’t have an active drag button, set it to the current button. That is, if
this.startAndReleaseDragOnPointerEvents
andthis.dragging
andthis._activeDragButton === -1
, setthis._activeDragButton
(but do nothing else, since the drag is already in progress). - Alternatively, in the pointer-up handler, if
this._activeDragButton
is -1, go ahead and release the drag without insisting it match the event’s button.
Playground link with a repro: Drag Behavior Programmatic | Babylon.js Playground (babylonjs.com)