Skip to content

Commit

Permalink
inspectKeyboardListeners is hidden behind an assertion, see #1570
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed Mar 26, 2024
1 parent a4c22d0 commit 983d2f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions js/input/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -794,17 +794,21 @@ export default class Input extends PhetioObject {
sceneryLog && sceneryLog.Input && sceneryLog.Input( `keydown(${Input.debugText( null, context.domEvent )});` );
sceneryLog && sceneryLog.Input && sceneryLog.push();

// Look for all global KeyboardListeners that are on Nodes that can receive input events. We will inspect
// this list for overlapping keys.
const keyboardListeners: KeyboardListener<OneKeyStroke[]>[] = [];
this.recursiveScanForGlobalKeyboardListeners( this.rootNode, keyboardListeners );

// Also add any local KeyboardListeners along the trail.
const trail = this.getPDOMEventTrail( context.domEvent, 'keydown' );
trail && this.scanTrailForKeyboardListeners( trail, keyboardListeners );

// Inspect listeners for overlapping keys.
KeyboardListener.inspectKeyboardListeners( keyboardListeners, context.domEvent );
if ( assert ) {

// Look for all global KeyboardListeners that are on Nodes that can receive input events. We will inspect
// this list for overlapping keys.
const keyboardListeners: KeyboardListener<OneKeyStroke[]>[] = [];
this.recursiveScanForGlobalKeyboardListeners( this.rootNode, keyboardListeners );

// Also add any local KeyboardListeners along the trail.
trail && this.scanTrailForKeyboardListeners( trail, keyboardListeners );

// Inspect listeners for overlapping keys.
KeyboardListener.inspectKeyboardListeners( keyboardListeners );
}

this.dispatchGlobalEvent<KeyboardEvent>( 'globalkeydown', context, true );

Expand Down
2 changes: 1 addition & 1 deletion js/listeners/KeyboardListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ class KeyboardListener<Keys extends readonly OneKeyStroke[]> extends EnabledComp
* - 'error': If any two listeners use the same keys, an error will be thrown.
* - 'allow': All key overlaps are allowed.
*/
public static inspectKeyboardListeners( keyboardListeners: KeyboardListener<OneKeyStroke[]>[], event: KeyboardEvent ): void {
public static inspectKeyboardListeners( keyboardListeners: KeyboardListener<OneKeyStroke[]>[] ): void {

// Collect KeyGroups with their listeners so can easily look up the listener when iterating through used keys.
const naturalKeysWithListener = keyboardListeners.reduce( ( accumulator: KeyGroupWithListener[], listener: KeyboardListener<OneKeyStroke[]> ) => {
Expand Down

0 comments on commit 983d2f1

Please sign in to comment.