Skip to content

Add a shorthand to create a shift+hotkey from a hotkey #1775

Description

@samreid

In phetsims/molecule-polarity#252 it looked like it wolud be useful to create one hotkey set as a shift + another hotkey set, like so:

Details
Subject: [PATCH] Add type HotkeySetVariant, see https://github.com/phetsims/scenery-phet/issues/963
---
Index: js/common/view/MPHotkeyData.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/common/view/MPHotkeyData.ts b/js/common/view/MPHotkeyData.ts
--- a/js/common/view/MPHotkeyData.ts	(revision c2684796e7534cf2e2149b7d4499248e65139da4)
+++ b/js/common/view/MPHotkeyData.ts	(date 1771377743230)
@@ -14,7 +14,7 @@
 
 export default class MPHotkeyData {
 
-  public constructor() {
+  private constructor() {
     // no-op
   }
 
@@ -31,9 +31,7 @@
    * HotkeyData for rotating molecule in smaller steps with shift + arrow keys
    */
   public static readonly ROTATE_MOLECULE_SMALLER_STEPS = new HotkeyData( {
-    keys: [
-      'shift+arrowLeft', 'shift+arrowRight', 'shift+arrowUp', 'shift+arrowDown'
-    ],
+    keys: MPHotkeyData.ROTATE_MOLECULE.keys.map( key => 'shift+' + key ),
     keyboardHelpDialogLabelStringProperty: MoleculePolarityFluent.a11y.common.keyboardHelpContent.rotateInSmallerStepsStringProperty,
     repoName: moleculePolarity.name
   } );
@@ -51,9 +49,7 @@
    * HotkeyData for rotating or moving in smaller steps with shift + arrow keys (Three Atoms screen)
    */
   public static readonly ROTATE_OR_MOVE_SMALLER_STEPS = new HotkeyData( {
-    keys: [
-      'shift+arrowLeft', 'shift+arrowRight', 'shift+arrowUp', 'shift+arrowDown'
-    ],
+    keys: MPHotkeyData.MOVE_ATOM_A_AND_C.keys.map( key => 'shift+' + key ),
     keyboardHelpDialogLabelStringProperty: MoleculePolarityFluent.a11y.common.keyboardHelpContent.rotateOrMoveInSmallerStepsStringProperty,
     repoName: moleculePolarity.name
   } );
@@ -73,9 +69,7 @@
    * HotkeyData for rotating molecule in smaller steps with shift + arrow/WASD keys (Real Molecules screen)
    */
   public static readonly ROTATE_MOLECULE_WASD_SMALLER_STEPS = new HotkeyData( {
-    keys: [
-      'shift+arrowLeft', 'shift+arrowRight', 'shift+arrowUp', 'shift+arrowDown', 'shift+w', 'shift+a', 'shift+s', 'shift+d'
-    ],
+    keys: MPHotkeyData.ROTATE_MOLECULE_WASD.keys.map( key => 'shift+' + key ),
     keyboardHelpDialogLabelStringProperty: MoleculePolarityFluent.a11y.common.keyboardHelpContent.rotateInSmallerStepsWASDStringProperty,
     repoName: moleculePolarity.name
   } );

This is more complex since the strings get mapped into properties. @jessegreenberg do you think this is a good idea? Do you see a way forward for it?

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions