@@ -274,8 +274,6 @@ if (!window.customElements.get('md-strikethrough')) {
274
274
window . customElements . define ( 'md-strikethrough' , MarkdownStrikethroughButtonElement )
275
275
}
276
276
277
- const modifierKey = navigator . userAgent . match ( / M a c i n t o s h / ) ? 'Meta' : 'Control'
278
-
279
277
class MarkdownToolbarElement extends HTMLElement {
280
278
constructor ( ) {
281
279
super ( )
@@ -286,21 +284,11 @@ class MarkdownToolbarElement extends HTMLElement {
286
284
this . setAttribute ( 'role' , 'toolbar' )
287
285
}
288
286
this . addEventListener ( 'keydown' , focusKeydown )
289
- const fn = shortcut . bind ( null , this )
290
- if ( this . field ) {
291
- this . field . addEventListener ( 'keydown' , fn )
292
- shortcutListeners . set ( this , fn )
293
- }
294
287
this . setAttribute ( 'tabindex' , '0' )
295
288
this . addEventListener ( 'focus' , onToolbarFocus , { once : true } )
296
289
}
297
290
298
291
disconnectedCallback ( ) : void {
299
- const fn = shortcutListeners . get ( this )
300
- if ( fn && this . field ) {
301
- this . field . removeEventListener ( 'keydown' , fn )
302
- shortcutListeners . delete ( this )
303
- }
304
292
this . removeEventListener ( 'keydown' , focusKeydown )
305
293
}
306
294
@@ -356,31 +344,6 @@ function focusKeydown(event: KeyboardEvent) {
356
344
buttons [ n ] . focus ( )
357
345
}
358
346
359
- const shortcutListeners = new WeakMap ( )
360
- function elementHotkeyRequiresShift ( element : Element ) : boolean {
361
- return element . hasAttribute ( 'hotkey-requires-shift' ) && element . getAttribute ( 'hotkey-requires-shift' ) !== 'false'
362
- }
363
-
364
- function findHotkey ( toolbar : Element , key : string , shiftPressed : boolean ) : HTMLElement | null {
365
- for ( const el of toolbar . querySelectorAll < HTMLElement > ( '[hotkey]' ) ) {
366
- if ( el . getAttribute ( 'hotkey' ) === key && ( ! elementHotkeyRequiresShift ( el ) || shiftPressed ) ) {
367
- return el
368
- }
369
- }
370
- return null
371
- }
372
-
373
- function shortcut ( toolbar : Element , event : KeyboardEvent ) {
374
- if ( ( event . metaKey && modifierKey === 'Meta' ) || ( event . ctrlKey && modifierKey === 'Control' ) ) {
375
- const key = event . shiftKey ? event . key . toUpperCase ( ) : event . key
376
- const button = findHotkey ( toolbar , key , event . shiftKey )
377
- if ( button ) {
378
- button . click ( )
379
- event . preventDefault ( )
380
- }
381
- }
382
- }
383
-
384
347
if ( ! window . customElements . get ( 'markdown-toolbar' ) ) {
385
348
window . MarkdownToolbarElement = MarkdownToolbarElement
386
349
window . customElements . define ( 'markdown-toolbar' , MarkdownToolbarElement )
0 commit comments