Skip to content

Commit

Permalink
implement dispose for global keyboard listeners see #1570
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed Apr 26, 2024
1 parent 1935e44 commit d7c453a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions js/listeners/KeyboardListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,21 @@ class GlobalKeyboardListener extends KeyboardListener<OneKeyStroke[]> {
globalHotkeyRegistry.add( hotkey );
} );
}

/**
* Dispose Properties and remove all Hotkeys from the global registry.
*/
public override dispose(): void {

// Remove all global keys from the registry.
this.hotkeys.forEach( hotkey => {
globalHotkeyRegistry.remove( hotkey );
} );

this.globallyEnabledProperty.dispose();
this.displayedTrailsProperty.dispose();
super.dispose();
}
}

scenery.register( 'KeyboardListener', KeyboardListener );
Expand Down

0 comments on commit d7c453a

Please sign in to comment.