google/blockly

Provide a way to get the current gesture (or current dragger) without passing an event

Opened this issue · 1 comments

Check for duplicates

  • I have searched for similar issues before opening a new one.

Problem

I just want to get the current gesture in progress on a workspace. Currently the only way to do this it to pass a PointerEvent. Ostensibly, you're supposed to pass in an event so that core can check if it's a pointerdown event and there's already a current gesture, that's an error. If there's not a current gesture but you pass a pointerdown event, it will start a new gesture.

I don't want that behavior. I just want to get the current dragger being used on the workspace, if there is one. For that, I need the current gesture. I don't want any risk of starting a new gesture and I don't have a PointerEvent to give it anyway.

Request / To fix

Make the e parameter to the WorkspaceSvg#getGesture method optional. If the parameter is not provided, just return this.currentGesture_.

If you'd like to work on this issue, please comment here so we can assign it to you. You can also read our contributing docs

Alternatives considered

Or provide a getCurrentGesture method that does the same. But then it's probably harder to explain the difference between the two.

Additional context

In the scroll-options plugin, we need to find out if there is a current drag in progress during a mouse wheel event

So I have the following monstrosity:

    // All we want to do is get the currentGesture from the workspace so
    // that we can get the dragger from it.
    // getGesture expects a PointerEvent, but we don't have one. As long
    // as the event we give it isn't a 'pointerdown' event, we'll get the
    // current gesture if there is one, or null if there isn't.
    const currentGesture = this.workspace_.getGesture(new PointerEvent('pointermove'));

You could also replace the last line with getGesture(e as unknown as PointerEvent) but that's equally as gross because e in this context is a WheelEvent which has nothing to do with the current gesture

tashee@ is going to work on this issue. I can't assign it directly yet, so just leaving this comment for now.