@@ -169,6 +169,11 @@ class MarkdownQuoteButtonElement extends MarkdownButtonElement {
169169 super ( )
170170 styles . set ( this , { prefix : '> ' , multiline : true , surroundWithNewlines : true } )
171171 }
172+
173+ connectedCallback ( ) {
174+ super . connectedCallback ( )
175+ this . setAttribute ( 'hotkey' , '.' )
176+ }
172177}
173178
174179if ( ! window . customElements . get ( 'md-quote' ) ) {
@@ -227,6 +232,11 @@ class MarkdownUnorderedListButtonElement extends MarkdownButtonElement {
227232 super ( )
228233 styles . set ( this , { prefix : '- ' , multiline : true , surroundWithNewlines : true } )
229234 }
235+ connectedCallback ( ) {
236+ super . connectedCallback ( )
237+ this . setAttribute ( 'hotkey' , '8' )
238+ this . setAttribute ( 'hotkey-requires-shift' , 'true' )
239+ }
230240}
231241
232242if ( ! window . customElements . get ( 'md-unordered-list' ) ) {
@@ -239,6 +249,11 @@ class MarkdownOrderedListButtonElement extends MarkdownButtonElement {
239249 super ( )
240250 styles . set ( this , { prefix : '1. ' , multiline : true , orderedList : true } )
241251 }
252+ connectedCallback ( ) {
253+ super . connectedCallback ( )
254+ this . setAttribute ( 'hotkey' , '9' )
255+ this . setAttribute ( 'hotkey-requires-shift' , 'true' )
256+ }
242257}
243258
244259if ( ! window . customElements . get ( 'md-ordered-list' ) ) {
@@ -382,10 +397,13 @@ function focusKeydown(event: KeyboardEvent) {
382397}
383398
384399const shortcutListeners = new WeakMap ( )
400+ function elementHotkeyRequiresShift ( element : Element ) : boolean {
401+ return element . hasAttribute ( 'hotkey-requires-shift' ) && element . getAttribute ( 'hotkey-requires-shift' ) !== 'false'
402+ }
385403
386- function findHotkey ( toolbar : Element , key : string ) : HTMLElement | null {
404+ function findHotkey ( toolbar : Element , key : string , shiftPressed : boolean ) : HTMLElement | null {
387405 for ( const el of toolbar . querySelectorAll < HTMLElement > ( '[hotkey]' ) ) {
388- if ( el . getAttribute ( 'hotkey' ) === key ) {
406+ if ( el . getAttribute ( 'hotkey' ) === key && ( ! elementHotkeyRequiresShift ( el ) || shiftPressed ) ) {
389407 return el
390408 }
391409 }
@@ -395,7 +413,7 @@ function findHotkey(toolbar: Element, key: string): HTMLElement | null {
395413function shortcut ( toolbar : Element , event : KeyboardEvent ) {
396414 if ( ( event . metaKey && modifierKey === 'Meta' ) || ( event . ctrlKey && modifierKey === 'Control' ) ) {
397415 const key = event . shiftKey ? event . key . toUpperCase ( ) : event . key
398- const button = findHotkey ( toolbar , key )
416+ const button = findHotkey ( toolbar , key , event . shiftKey )
399417 if ( button ) {
400418 button . click ( )
401419 event . preventDefault ( )
0 commit comments