@@ -52,19 +52,6 @@ export class ShortcutDialog {
5252 }
5353 }
5454
55- /**
56- * Update the modifier key to the user's specific platform.
57- */
58- updatePlatformName ( ) {
59- const platform = this . getPlatform ( ) ;
60- const platformEl = this . outputDiv
61- ? this . outputDiv . querySelector ( '.platform' )
62- : null ;
63- if ( platformEl ) {
64- platformEl . textContent = platform ;
65- }
66- }
67-
6855 toggle ( workspace : Blockly . WorkspaceSvg ) {
6956 clearHelpHint ( workspace ) ;
7057 this . toggleInternal ( ) ;
@@ -88,54 +75,56 @@ export class ShortcutDialog {
8875 * @returns A title case version of the name.
8976 */
9077 getReadableShortcutName ( shortcutName : string ) {
78+ if ( Constants . SHORTCUT_NAMES_TO_DISPLAY_TEXT [ shortcutName ] ) {
79+ return Constants . SHORTCUT_NAMES_TO_DISPLAY_TEXT [ shortcutName ] ;
80+ }
9181 return upperCaseFirst ( shortcutName . replace ( / _ / gi, ' ' ) ) ;
9282 }
9383
9484 /**
9585 * List all currently registered shortcuts as a table.
9686 */
9787 createModalContent ( ) {
98- let modalContents = `<div class="modal-container">
99- <dialog class="shortcut-modal">
100- <div class="shortcut-container" tabindex="0">
101- <div class="header">
102- <button class="close-modal">
103- <span class="material-symbols-outlined">close</span>
104- </button>
105- <h1>Keyboard shortcuts – <span class="platform">Windows</span></h1>
106- </div>
107- <div class="shortcut-tables">` ;
88+ let shortcutTables = `` ;
10889
10990 // Display shortcuts by their categories.
11091 for ( const [ key , categoryShortcuts ] of Object . entries (
11192 Constants . SHORTCUT_CATEGORIES ,
11293 ) ) {
113- modalContents += `
114- <table class="shortcut-table">
115- <tbody>
116- <tr class="category"><th colspan="3"><h2>${ key } </h2></th></tr>
117- <tr>
118- ` ;
119-
94+ let shortcutTableRows = `` ;
12095 for ( const keyboardShortcut of categoryShortcuts ) {
121- modalContents += `
122- <td>${ this . getReadableShortcutName ( keyboardShortcut ) } </td>
123- <td>${ this . actionShortcutsToHTML ( keyboardShortcut ) } </td>
124- </tr>` ;
96+ shortcutTableRows += this . getTableRowForShortcut (
97+ keyboardShortcut as string ,
98+ ) ;
12599 }
126- modalContents += '</tr></tbody></table>' ;
100+ shortcutTables += `
101+ <table class="shortcut-table">
102+ <tbody>
103+ <tr class="category"><th colspan="3"><h2>${ key } </h2></th></tr>
104+ ${ shortcutTableRows }
105+ </tbody>
106+ </table>` ;
127107 }
108+
109+ const modalContents = `<div class="modal-container">
110+ <dialog class="shortcut-modal">
111+ <div class="shortcut-container" tabindex="0">
112+ <div class="header">
113+ <button class="close-modal">
114+ <span class="material-symbols-outlined">close</span>
115+ </button>
116+ <h1>${ Msg [ 'SHORTCUTS_HELP_HEADER' ] || 'Keyboard shortcuts' } – <span class="platform">${ this . getPlatform ( ) } </span></h1>
117+ </div>
118+ <div class="shortcut-tables">
119+ ${ shortcutTables }
120+ </div>
121+ </dialog>
122+ </div>` ;
128123 if ( this . outputDiv ) {
129- this . outputDiv . innerHTML =
130- modalContents +
131- `</div>
132- </dialog>
133- </div>` ;
124+ this . outputDiv . innerHTML = modalContents ;
134125 this . modalContainer = this . outputDiv . querySelector ( '.modal-container' ) ;
135126 this . shortcutDialog = this . outputDiv . querySelector ( '.shortcut-modal' ) ;
136127 this . closeButton = this . outputDiv . querySelector ( '.close-modal' ) ;
137- this . updatePlatformName ( ) ;
138- // Can we also intercept the Esc key to dismiss.
139128 if ( this . closeButton ) {
140129 this . closeButton . addEventListener ( 'click' , ( e ) => {
141130 this . toggleInternal ( ) ;
@@ -144,13 +133,25 @@ export class ShortcutDialog {
144133 }
145134 }
146135
136+ private getTableRowForShortcut ( keyboardShortcut : string ) {
137+ const name = this . getReadableShortcutName ( keyboardShortcut ) ;
138+ const keys = this . actionShortcutsToHTML ( keyboardShortcut ) ;
139+ if ( ! name || ! keys ) return '' ;
140+ return `
141+ <tr>
142+ <td>${ name } </td>
143+ <td>${ keys } </td>
144+ </tr>` ;
145+ }
146+
147147 private actionShortcutsToHTML ( action : string ) {
148148 const shortcuts = getLongActionShortcutsAsKeys ( action ) ;
149- return shortcuts . map ( ( keys ) => this . actionShortcutToHTML ( keys ) ) . join ( ' / ' ) ;
149+ return shortcuts . map ( ( keys ) => this . keysToHTML ( keys ) ) . join ( ' / ' ) ;
150150 }
151151
152- private actionShortcutToHTML ( keys : string [ ] ) {
152+ private keysToHTML ( keys : string [ ] ) {
153153 const separator = navigator . platform . startsWith ( 'Mac' ) ? '' : ' + ' ;
154+ if ( ! keys || ! keys . length ) return '' ;
154155 return [
155156 `<span class="shortcut-combo">` ,
156157 ...keys . map ( ( key , index ) => {
0 commit comments