@@ -169,6 +169,11 @@ class MarkdownQuoteButtonElement extends MarkdownButtonElement {
169
169
super ( )
170
170
styles . set ( this , { prefix : '> ' , multiline : true , surroundWithNewlines : true } )
171
171
}
172
+
173
+ connectedCallback ( ) {
174
+ super . connectedCallback ( )
175
+ this . setAttribute ( 'hotkey' , '.' )
176
+ }
172
177
}
173
178
174
179
if ( ! window . customElements . get ( 'md-quote' ) ) {
@@ -227,6 +232,11 @@ class MarkdownUnorderedListButtonElement extends MarkdownButtonElement {
227
232
super ( )
228
233
styles . set ( this , { prefix : '- ' , multiline : true , surroundWithNewlines : true } )
229
234
}
235
+ connectedCallback ( ) {
236
+ super . connectedCallback ( )
237
+ this . setAttribute ( 'hotkey' , '8' )
238
+ this . setAttribute ( 'hotkey-requires-shift' , 'true' )
239
+ }
230
240
}
231
241
232
242
if ( ! window . customElements . get ( 'md-unordered-list' ) ) {
@@ -239,6 +249,11 @@ class MarkdownOrderedListButtonElement extends MarkdownButtonElement {
239
249
super ( )
240
250
styles . set ( this , { prefix : '1. ' , multiline : true , orderedList : true } )
241
251
}
252
+ connectedCallback ( ) {
253
+ super . connectedCallback ( )
254
+ this . setAttribute ( 'hotkey' , '9' )
255
+ this . setAttribute ( 'hotkey-requires-shift' , 'true' )
256
+ }
242
257
}
243
258
244
259
if ( ! window . customElements . get ( 'md-ordered-list' ) ) {
@@ -382,10 +397,13 @@ function focusKeydown(event: KeyboardEvent) {
382
397
}
383
398
384
399
const shortcutListeners = new WeakMap ( )
400
+ function elementHotkeyRequiresShift ( element : Element ) : boolean {
401
+ return element . hasAttribute ( 'hotkey-requires-shift' ) && element . getAttribute ( 'hotkey-requires-shift' ) !== 'false'
402
+ }
385
403
386
- function findHotkey ( toolbar : Element , key : string ) : HTMLElement | null {
404
+ function findHotkey ( toolbar : Element , key : string , shiftPressed : boolean ) : HTMLElement | null {
387
405
for ( const el of toolbar . querySelectorAll < HTMLElement > ( '[hotkey]' ) ) {
388
- if ( el . getAttribute ( 'hotkey' ) === key ) {
406
+ if ( el . getAttribute ( 'hotkey' ) === key && ( ! elementHotkeyRequiresShift ( el ) || shiftPressed ) ) {
389
407
return el
390
408
}
391
409
}
@@ -395,7 +413,7 @@ function findHotkey(toolbar: Element, key: string): HTMLElement | null {
395
413
function shortcut ( toolbar : Element , event : KeyboardEvent ) {
396
414
if ( ( event . metaKey && modifierKey === 'Meta' ) || ( event . ctrlKey && modifierKey === 'Control' ) ) {
397
415
const key = event . shiftKey ? event . key . toUpperCase ( ) : event . key
398
- const button = findHotkey ( toolbar , key )
416
+ const button = findHotkey ( toolbar , key , event . shiftKey )
399
417
if ( button ) {
400
418
button . click ( )
401
419
event . preventDefault ( )
0 commit comments