@@ -4,34 +4,39 @@ import {keyNames} from './keynames';
44const isMacPlatform = navigator . platform . startsWith ( 'Mac' ) ;
55
66/**
7- * Format the primary shortcut for this platform in a user facing format.
7+ * Find the primary shortcut for this platform and return it as single string
8+ * in a short user facing format.
89 *
910 * @param action The action name, e.g. "cut".
10- * @param format The key format.
1111 * @returns The formatted shortcut.
1212 */
13- export function formatActionShortcut (
14- action : string ,
15- format : ShortcutFormat ,
16- ) : string {
17- const parts = actionShortcutsForPlatform ( action , format ) [ 0 ] ;
13+ export function getShortActionShortcut ( action : string ) : string {
14+ const parts = getActionShortcutsAsKeys ( action , shortModifierNames ) [ 0 ] ;
1815 return parts . join ( isMacPlatform ? ' ' : ' + ' ) ;
1916}
2017
21- const modifierNamesByFormat : Record < ShortcutFormat , Record < string , string > > = {
22- long : {
23- 'Control' : 'Ctrl' ,
24- 'Meta' : '⌘ Command' ,
25- 'Alt' : isMacPlatform ? '⌥ Option' : 'Alt' ,
26- } ,
27- short : {
28- 'Control' : 'Ctrl' ,
29- 'Meta' : '⌘' ,
30- 'Alt' : isMacPlatform ? '⌥' : 'Alt' ,
31- } ,
18+ /**
19+ * Find the relevant shortcuts for the given action for the current platform.
20+ * Keys are returned in a long user facing format.
21+ *
22+ * @param action The action name, e.g. "cut".
23+ * @returns The formatted shortcuts as individual keys.
24+ */
25+ export function getLongActionShortcutsAsKeys ( action : string ) : string [ ] [ ] {
26+ return getActionShortcutsAsKeys ( action , longModifierNames ) ;
27+ }
28+
29+ const longModifierNames : Record < string , string > = {
30+ 'Control' : 'Ctrl' ,
31+ 'Meta' : '⌘ Command' ,
32+ 'Alt' : isMacPlatform ? '⌥ Option' : 'Alt' ,
3233} ;
3334
34- export type ShortcutFormat = 'long' | 'short' ;
35+ const shortModifierNames : Record < string , string > = {
36+ 'Control' : 'Ctrl' ,
37+ 'Meta' : '⌘' ,
38+ 'Alt' : isMacPlatform ? '⌥' : 'Alt' ,
39+ } ;
3540
3641/**
3742 * Find the relevant shortcuts for the given action for the current platform.
@@ -41,14 +46,13 @@ export type ShortcutFormat = 'long' | 'short';
4146 * current platform or tagged them with a platform.
4247 *
4348 * @param action The action name, e.g. "cut".
44- * @param format The key format .
49+ * @param modifierNames The names to use for the Meta/Control/Alt modifiers .
4550 * @returns The formatted shortcuts.
4651 */
47- export function actionShortcutsForPlatform (
52+ function getActionShortcutsAsKeys (
4853 action : string ,
49- format : ShortcutFormat ,
54+ modifierNames : Record < string , string > ,
5055) : string [ ] [ ] {
51- const modifierNames = modifierNamesByFormat [ format ] ;
5256 const shortcuts = ShortcutRegistry . registry . getKeyCodesByShortcutName ( action ) ;
5357 // See ShortcutRegistry.createSerializedKey for the starting format.
5458 const named = shortcuts . map ( ( shortcut ) => {
0 commit comments