@@ -8,7 +8,7 @@ import * as Blockly from 'blockly/core';
88import * as Constants from './constants' ;
99import { ShortcutRegistry } from 'blockly/core' ;
1010// @ts -expect-error No types in js file
11- import { keyCodeArrayToString } from './keynames' ;
11+ import { keyCodeArrayToString , toTitleCase } from './keynames' ;
1212
1313/**
1414 * Class for handling the shortcuts dialog.
@@ -96,7 +96,7 @@ export class ShortcutDialog {
9696 * @returns {string }
9797 */
9898 getReadableShortcutName ( shortcutName : string ) {
99- shortcutName = shortcutName . replace ( / _ / gi, ' ' ) ;
99+ shortcutName = toTitleCase ( shortcutName . replace ( / _ / gi, ' ' ) ) ;
100100 return shortcutName ;
101101 }
102102
@@ -107,38 +107,38 @@ export class ShortcutDialog {
107107 const registry = ShortcutRegistry . registry . getRegistry ( ) ;
108108
109109 let modalContents = `<div class="modal-container">
110- <dialog class="shortcut-modal">
111- <div class="shortcut-container">
112- <div class="header">
113- <button class="close-modal">
114- <span class="material-symbols-outlined">close</span>
115- </button>
116- <h1>Keyboard shortcuts</h1>
117- <p class="intro">
118- <span class="platform">Windows</span>
119- </p>
120- </div>
121- <div class="shortcut-container">
122- <table class="shortcuts">
123- <tbody>
124- ` ;
110+ <dialog class="shortcut-modal">
111+ <div class="shortcut-container">
112+ <div class="header">
113+ <button class="close-modal">
114+ <span class="material-symbols-outlined">close</span>
115+ </button>
116+ <h1>Keyboard shortcuts – <span class="platform">Windows</span></h1>
117+ </div>
118+ <div class="shortcut-tables">` ;
125119
126120 // Display shortcuts by their categories.
127121 const categoryKeys = Object . keys ( Constants . SHORTCUT_CATEGORIES ) ;
122+
128123 for ( const key of categoryKeys ) {
129124 const categoryShortcuts : string [ ] =
130125 Constants . SHORTCUT_CATEGORIES [
131126 key as keyof typeof Constants . SHORTCUT_CATEGORIES
132127 ] ;
133128
129+ const shortcuts = Object . keys ( registry ) ;
130+
134131 modalContents += `
135- <thead>
136- <tr class="category">
137- <th colspan="2">${ key } </th>
138- </tr>
139- </thead>
132+ <table class="shortcut-table">
133+ <tbody>
134+ <tr class="category"><th colspan="3"><h2>${ key } </h2></th></tr>
135+ <tr>
140136 ` ;
141- for ( const keyboardShortcut of Object . keys ( registry ) ) {
137+
138+ for ( const keyboardShortcut of shortcuts ) {
139+ console . log ( keyboardShortcut , ShortcutRegistry . registry . getKeyCodesByShortcutName (
140+ keyboardShortcut
141+ ) ) ;
142142 if ( categoryShortcuts . includes ( keyboardShortcut ) ) {
143143 const codeArray =
144144 ShortcutRegistry . registry . getKeyCodesByShortcutName (
@@ -150,19 +150,18 @@ export class ShortcutDialog {
150150 ? keyCodeArrayToString ( codeArray . slice ( 0 , 1 ) )
151151 : keyCodeArrayToString ( codeArray ) ;
152152
153- modalContents += `<tr>
153+ modalContents += `
154154 <td>${ this . getReadableShortcutName ( keyboardShortcut ) } </td>
155155 <td>${ prettyPrinted } </td>
156156 </tr>` ;
157157 }
158158 }
159+ modalContents += '</tr></tbody></table>' ;
159160 }
160161 if ( this . outputDiv ) {
161162 this . outputDiv . innerHTML =
162163 modalContents +
163- `\n</tbody>
164- </table>
165- </div>
164+ `</div>
166165 </dialog>
167166 </div>` ;
168167 this . modalContainer = this . outputDiv . querySelector ( '.modal-container' ) ;
@@ -185,9 +184,9 @@ export class ShortcutDialog {
185184 **/
186185Blockly . Css . register ( `
187186:root {
188- --divider-border-color: #DADCE0 ;
189- --key-border-color: #BDC1C6 ;
190- --shortcut-modal-border-color: #9AA0A6 ;
187+ --divider-border-color: #eee ;
188+ --key-border-color: #ccc ;
189+ --shortcut-modal-border-color: #9aa0a6 ;
191190}
192191
193192.modal-container {
@@ -205,16 +204,15 @@ Blockly.Css.register(`
205204.shortcut-modal {
206205 border: 1px solid var(--shortcut-modal-border-color);
207206 border-radius: 12px;
208- box-shadow: 6px 6px 32px rgba(0,0,0,.5);
207+ box-shadow: 6px 6px 32px rgba(0,0,0,.5);
209208 flex-direction: column;
210209 gap: 12px;
211210 margin: auto;
212211 max-height: 82vh;
213- max-width: 800px;
214- min-width: 300px;
212+ min-width: 500px;
215213 padding: 24px 12px 24px 32px;
216214 position: relative;
217- width: 50% ;
215+ width: calc(100% - 10em) ;
218216 z-index: 99;
219217}
220218
@@ -235,62 +233,111 @@ Blockly.Css.register(`
235233
236234.modal-container h1 {
237235 font-weight: 600;
238- font-size: 1.5em ;
236+ font-size: 1.2em ;
239237}
240238
241239.modal-container {
242240 background: radial-gradient(rgba(244, 244, 244, 0.43), rgba(75, 75, 75, 0.51));
243241}
244242
245- .shortcuts {
246- width: 100%;
247- font-family: Roboto;
243+ .shortcut-table {
248244 border-collapse: collapse;
245+ font-family: Roboto;
249246 font-size: .9em;
247+ width: 100%;
250248}
251249
252- .shortcuts th {
250+ .shortcut-table th {
251+ padding-inline-end: 0.5em;
253252 text-align: left;
254- padding: 1em 0 0.5em;
253+ text-wrap: nowrap;
254+ vertical-align: baseline;
255255}
256256
257- .shortcuts .key {
258- border-radius: 8px ;
259- border: 1px solid var(--key-border-color) ;
260- display: inline-block;
261- margin: 0 8px;
262- min-width: 2em;
263- padding: .5em .5em ;
264- text-align: center ;
257+ .shortcut-table td:first-child {
258+ text-wrap: auto ;
259+ width: 40% ;
260+ }
261+
262+ .shortcut-table tr:has(+ .category) {
263+ --divider-border-color: transparent ;
264+ margin-end: 1em ;
265265}
266266
267- .shortcuts tr:not(.category, :last-child) {
267+ .shortcut-table tr:not(.category, :last-child) {
268268 border-bottom: 1px solid var(--divider-border-color);
269269}
270270
271- .shortcuts td {
272- padding: .5em 1em .6em 0;
273- text-wrap: nowrap
271+ .shortcut-table td {
272+ padding: 0.2em 1em 0.3em 0;
273+ text-wrap: nowrap;
274274}
275275
276- .shortcut-container {
277- overflow: auto;
276+ .shortcut-table h2 {
277+ border-bottom: 1px solid #999;
278+ font-size: 1em;
279+ padding-block-end: 0.5em;
278280}
279281
280- .shortcuts .separator {
282+ .shortcut-table .key {
283+ border: 1px solid var(--key-border-color);
284+ border-radius: 8px;
281285 display: inline-block;
282- padding: 0 0.5em;
286+ margin: 0 8px;
287+ min-width: 2em;
288+ padding: .3em .5em;
289+ text-align: center;
290+ }
291+
292+ .shortcut-table .separator {
283293 color: gray;
294+ display: inline-block;
295+ padding: 0 0.5em;
296+ }
297+
298+ .shortcut-container {
299+ font-size: 0.95em;
300+ overflow: auto;
301+ padding-inline-end: .5em;
284302}
285303
286304.shortcut-combo {
287- text-wrap: nowrap;
288305 display: inline-block;
289306 padding: 0.25em 0;
307+ text-wrap: nowrap;
308+ }
309+
310+ @media (max-width: 800px) {
311+ .shortcut-modal {
312+ min-width: 450px;
313+ }
314+ }
315+
316+ @media (min-width: 1024px) {
317+ .shortcut-tables {
318+ align-items: flex-start;
319+ display: flex;
320+ flex-wrap: wrap;
321+ justify-content: space-between;
322+ }
323+
324+ .shortcut-table {
325+ width: calc(50% - 12px);
326+ }
290327}
291328
292- .shortcuts tr td:first-child {
293- text-transform: capitalize;
329+ @media (min-width: 1420px) {
330+ .shortcut-modal {
331+ max-width: 1900px
332+ }
333+
334+ .shortcut-table {
335+ width: calc(25% - 24px);
336+ }
337+
338+ .shortcut-table td:first-child {
339+ width: 45%;
340+ }
294341}
295342
296343` ) ;
0 commit comments