77import * as Blockly from 'blockly/core' ;
88import * as Constants from './constants' ;
99import { ShortcutRegistry } from 'blockly/core' ;
10- import { keyCodeArrayToString , toTitleCase } from './keynames' ;
10+ import {
11+ getLongActionShortcutsAsKeys ,
12+ upperCaseFirst ,
13+ } from './shortcut_formatting' ;
1114
1215/**
1316 * Class for handling the shortcuts dialog.
@@ -51,28 +54,14 @@ export class ShortcutDialog {
5154 /**
5255 * Update the modifier key to the user's specific platform.
5356 */
54- updatePlatformModifier ( ) {
57+ updatePlatformName ( ) {
5558 const platform = this . getPlatform ( ) ;
5659 const platformEl = this . outputDiv
5760 ? this . outputDiv . querySelector ( '.platform' )
5861 : null ;
59-
60- // Update platform string
6162 if ( platformEl ) {
6263 platformEl . textContent = platform ;
6364 }
64-
65- if ( this . shortcutDialog ) {
66- const modifierKeys =
67- this . shortcutDialog . querySelectorAll ( '.key.modifier' ) ;
68-
69- if ( modifierKeys . length > 0 && platform ) {
70- for ( const key of modifierKeys ) {
71- key . textContent =
72- this . getPlatform ( ) === 'macOS' ? '⌘ Command' : 'Ctrl' ;
73- }
74- }
75- }
7665 }
7766
7867 toggle ( ) {
@@ -93,7 +82,7 @@ export class ShortcutDialog {
9382 * @returns A title case version of the name.
9483 */
9584 getReadableShortcutName ( shortcutName : string ) {
96- return toTitleCase ( shortcutName . replace ( / _ / gi, ' ' ) ) ;
85+ return upperCaseFirst ( shortcutName . replace ( / _ / gi, ' ' ) ) ;
9786 }
9887
9988 /**
@@ -123,20 +112,10 @@ export class ShortcutDialog {
123112 ` ;
124113
125114 for ( const keyboardShortcut of categoryShortcuts ) {
126- const codeArray =
127- ShortcutRegistry . registry . getKeyCodesByShortcutName ( keyboardShortcut ) ;
128- if ( codeArray . length > 0 ) {
129- // Only show the first shortcut if there are many
130- const prettyPrinted =
131- codeArray . length > 2
132- ? keyCodeArrayToString ( codeArray . slice ( 0 , 1 ) )
133- : keyCodeArrayToString ( codeArray ) ;
134-
135- modalContents += `
115+ modalContents += `
136116 <td>${ this . getReadableShortcutName ( keyboardShortcut ) } </td>
137- <td>${ prettyPrinted } </td>
117+ <td>${ this . actionShortcutsToHTML ( keyboardShortcut ) } </td>
138118 </tr>` ;
139- }
140119 }
141120 modalContents += '</tr></tbody></table>' ;
142121 }
@@ -149,7 +128,7 @@ export class ShortcutDialog {
149128 this . modalContainer = this . outputDiv . querySelector ( '.modal-container' ) ;
150129 this . shortcutDialog = this . outputDiv . querySelector ( '.shortcut-modal' ) ;
151130 this . closeButton = this . outputDiv . querySelector ( '.close-modal' ) ;
152- this . updatePlatformModifier ( ) ;
131+ this . updatePlatformName ( ) ;
153132 // Can we also intercept the Esc key to dismiss.
154133 if ( this . closeButton ) {
155134 this . closeButton . addEventListener ( 'click' , ( e ) => {
@@ -159,6 +138,22 @@ export class ShortcutDialog {
159138 }
160139 }
161140
141+ private actionShortcutsToHTML ( action : string ) {
142+ const shortcuts = getLongActionShortcutsAsKeys ( action ) ;
143+ return shortcuts . map ( ( keys ) => this . actionShortcutToHTML ( keys ) ) . join ( ' / ' ) ;
144+ }
145+
146+ private actionShortcutToHTML ( keys : string [ ] ) {
147+ const separator = navigator . platform . startsWith ( 'Mac' ) ? '' : ' + ' ;
148+ return [
149+ `<span class="shortcut-combo">` ,
150+ ...keys . map ( ( key , index ) => {
151+ return `<span class="key">${ key } </span>${ index < keys . length - 1 ? separator : '' } ` ;
152+ } ) ,
153+ `</span>` ,
154+ ] . join ( '' ) ;
155+ }
156+
162157 /**
163158 * Registers an action to list shortcuts with the shortcut registry.
164159 */
@@ -304,7 +299,7 @@ Blockly.Css.register(`
304299 border: 1px solid var(--key-border-color);
305300 border-radius: 8px;
306301 display: inline-block;
307- margin: 0 8px ;
302+ margin: 0 4px ;
308303 min-width: 2em;
309304 padding: .3em .5em;
310305 text-align: center;
0 commit comments