Skip to content

Conversation

@rachel-fenichel
Copy link
Collaborator

Fixes #393

Adds an additional monkeypatch to the workspace. The current Gesture is always null during a keyboard drag, and trying to get a gesture also stops propagation and prevents default on the instigating event.

Without this patch, WorkspaceSvg automatically creates a new Gesture if none was found:

  getGesture(e: PointerEvent): Gesture | null {
    const isStart = e.type === 'pointerdown';

    const gesture = this.currentGesture_;
    if (gesture) {
      if (isStart && gesture.hasStarted()) {
        console.warn('Tried to start the same gesture twice.');
        // That's funny.  We must have missed a mouse up.
        // Cancel it, rather than try to retrieve all of the state we need.
        gesture.cancel();
        return null;
      }
      return gesture;
    }

    // No gesture existed on this workspace, but this looks like the start of a
    // new gesture.
    if (isStart) {
      this.currentGesture_ = new Gesture(e, this);
      return this.currentGesture_;
    }
    // No gesture existed and this event couldn't be the start of a new gesture.
    return null;
  }

The workspace then calls handleWsStart when the event propagates to the workspace, and handleWsStart calls stopPropagation and preventDefault on the event.

Since `handlWsStart is not called in the new approach, directly cancel propagation in the getter.

Additional information

As with anything marked as a monkeypatch, this will need formalization into core.

@rachel-fenichel rachel-fenichel requested a review from a team as a code owner April 7, 2025 21:10
@rachel-fenichel rachel-fenichel requested review from RoboErikG and maribethb and removed request for a team and RoboErikG April 7, 2025 21:10
);

this.unpatchIsDragging(workspace);
this.upatchWorkspace(workspace);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: should be unpatch not upatch

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d'oh. fixed.

@rachel-fenichel rachel-fenichel merged commit e3897e0 into RaspberryPiFoundation:main Apr 8, 2025
2 checks passed
@rachel-fenichel rachel-fenichel deleted the click_during_drag branch April 8, 2025 16:46
* The stashed getGesture function, which is replaced at the beginning
* of a keyboard drag and reset at the end of a keyboard drag.
*/
oldGetGesture: ((e: PointerEvent) => Gesture | null) | null = null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been per-workspace (and patching/unpatching handled carefully) because Mover can handle multiple simultaneous moves on one or more workspaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mouse interactions cause odd behaviour during an in-progress keyboard move

3 participants