Programmatically-started drags can no longer be completed by clicking

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:

  1. 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 and this.dragging and this._activeDragButton === -1, set this._activeDragButton (but do nothing else, since the drag is already in progress).
  2. 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)

Hey @mattdmorgan,
Lemme take a look at what’s going on.

Sorry about the delay on this. I’ve tested a bunch of scenarios and your #2 fix worked perfectly. Fix is in PR: PointerDragBehavior: Added check to force releaseDrag to fire when no active button is present by PolygonalSun · Pull Request #13578 · BabylonJS/Babylon.js (github.com)

2 Likes

PR is merged

Great, thanks!