Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultiListener doesn't work for particular Trails #1587

Open
jessegreenberg opened this issue Nov 20, 2023 · 0 comments
Open

MultiListener doesn't work for particular Trails #1587

jessegreenberg opened this issue Nov 20, 2023 · 0 comments
Assignees

Comments

@jessegreenberg
Copy link
Contributor

I was trying MultiListener outside of a PhET simulation and needed this patch to get it to work for my scene. Seems like a reasonable change but it should be cleaned and tested.

Subject: [PATCH] focusPanDirection -> limitPanDirection, see https://github.com/phetsims/center-and-variability/issues/564
---
Index: js/listeners/MultiListener.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/listeners/MultiListener.ts b/js/listeners/MultiListener.ts
--- a/js/listeners/MultiListener.ts	(revision 46bd74b3cf1d8d7bbfb6fe875b6579b920712470)
+++ b/js/listeners/MultiListener.ts	(date 1700409247479)
@@ -342,24 +342,29 @@
     }
     assert && assert( _.includes( pressTrail.nodes, this._targetNode ), 'targetNode must be in the Trail for Press' );
 
-    sceneryLog && sceneryLog.InputListener && sceneryLog.push();
-    const press = new MultiListenerPress( event.pointer, pressTrail );
+    // If this targetNode is not in the event trail, and the event target does not have a trail that contains
+    // the targetNode, then we should not add a press. This can happen when the targetNode is not in a subtree
+    // under this targetNode (like when it is in a modal pane), and we don't want to add a press in that case.
+    if ( pressTrail ) {
+      sceneryLog && sceneryLog.InputListener && sceneryLog.push();
+      const press = new MultiListenerPress( event.pointer, pressTrail );
 
-    if ( !this._allowMoveInterruption && !this._allowMultitouchInterruption ) {
+      if ( !this._allowMoveInterruption && !this._allowMultitouchInterruption ) {
 
-      // most restrictive case, only allow presses if the pointer is not attached - Presses
-      // are never added as background presses in this case because interruption is never allowed
-      if ( !event.pointer.isAttached() ) {
-        sceneryLog && sceneryLog.InputListener && sceneryLog.InputListener( 'MultiListener unattached, using press' );
-        this.addPress( press );
-      }
-    }
-    else {
+        // most restrictive case, only allow presses if the pointer is not attached - Presses
+        // are never added as background presses in this case because interruption is never allowed
+        if ( !event.pointer.isAttached() ) {
+          sceneryLog && sceneryLog.InputListener && sceneryLog.InputListener( 'MultiListener unattached, using press' );
+          this.addPress( press );
+        }
+      }
+      else {
 
-      // we allow some form of interruption, add as background presses, and we will decide if they
-      // should be converted to presses and interrupt other listeners on move event
-      sceneryLog && sceneryLog.InputListener && sceneryLog.InputListener( 'MultiListener attached, adding background press' );
-      this.addBackgroundPress( press );
+        // we allow some form of interruption, add as background presses, and we will decide if they
+        // should be converted to presses and interrupt other listeners on move event
+        sceneryLog && sceneryLog.InputListener && sceneryLog.InputListener( 'MultiListener attached, adding background press' );
+        this.addBackgroundPress( press );
+      }
     }
 
     sceneryLog && sceneryLog.InputListener && sceneryLog.pop();
@jessegreenberg jessegreenberg self-assigned this Nov 20, 2023
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

No branches or pull requests

1 participant