Skip to content

Commit

Permalink
Fixing hotkeyManager when the main key is included in general modifie…
Browse files Browse the repository at this point in the history
…rKeys, see #1621
  • Loading branch information
jonathanolson committed Mar 28, 2024
1 parent 2067fa6 commit 94ed63b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions js/input/Hotkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export default class Hotkey extends EnabledComponent {
public readonly fireOnHoldTiming: HotkeyFireOnHoldTiming;
public readonly allowOverlap: boolean;

// All keys that are part of this hotkey (key + modifierKeys)
public readonly keys: EnglishKey[];

// A Property that tracks whether the hotkey is currently pressed.
// Will be true if it meets the following conditions:
//
Expand Down Expand Up @@ -126,6 +129,8 @@ export default class Hotkey extends EnabledComponent {
this.fireOnHoldTiming = options.fireOnHoldTiming;
this.allowOverlap = options.allowOverlap;

this.keys = _.uniq( [ this.key, ...this.modifierKeys ] );

// Create a timer to handle the optional fire-on-hold feature.
if ( this.fireOnHold && this.fireOnHoldTiming === 'custom' ) {
this.fireOnHoldTimer = new CallbackTimer( {
Expand Down
4 changes: 3 additions & 1 deletion js/input/hotkeyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,15 @@ class HotkeyManager {
}

const compatibleKeys = [ ...this.enabledHotkeysProperty.value ].filter( hotkey => {

// Filter out hotkeys that don't have the main key
if ( hotkey.key !== mainKey ) {
return false;
}

// See whether the modifier keys match
return this.modifierKeys.every( modifierKey => {
return this.englishKeysDown.has( modifierKey ) === hotkey.modifierKeys.includes( modifierKey ) ||
return this.englishKeysDown.has( modifierKey ) === hotkey.keys.includes( modifierKey ) ||
hotkey.ignoredModifierKeys.includes( modifierKey );
} );
} );
Expand All @@ -215,6 +216,7 @@ class HotkeyManager {
* there are no conflicts).
*/
private updateHotkeyStatus( keyboardEvent: KeyboardEvent | null ): void {

// For fireOnDown on/off cases, we only want to fire the hotkeys when we have a keyboard event specifying hotkey's
// main `key`.
const pressedOrReleasedKeyCode = KeyboardUtils.getEventCode( keyboardEvent );
Expand Down

0 comments on commit 94ed63b

Please sign in to comment.