@@ -135,11 +135,6 @@ class MarkdownBoldButtonElement extends MarkdownButtonElement {
135
135
super ( )
136
136
styles . set ( this , { prefix : '**' , suffix : '**' , trimFirst : true } )
137
137
}
138
-
139
- connectedCallback ( ) {
140
- super . connectedCallback ( )
141
- this . setAttribute ( 'hotkey' , 'b' )
142
- }
143
138
}
144
139
145
140
if ( ! window . customElements . get ( 'md-bold' ) ) {
@@ -152,11 +147,6 @@ class MarkdownItalicButtonElement extends MarkdownButtonElement {
152
147
super ( )
153
148
styles . set ( this , { prefix : '_' , suffix : '_' , trimFirst : true } )
154
149
}
155
-
156
- connectedCallback ( ) {
157
- super . connectedCallback ( )
158
- this . setAttribute ( 'hotkey' , 'i' )
159
- }
160
150
}
161
151
162
152
if ( ! window . customElements . get ( 'md-italic' ) ) {
@@ -169,12 +159,6 @@ class MarkdownQuoteButtonElement extends MarkdownButtonElement {
169
159
super ( )
170
160
styles . set ( this , { prefix : '> ' , multiline : true , surroundWithNewlines : true } )
171
161
}
172
-
173
- connectedCallback ( ) {
174
- super . connectedCallback ( )
175
- this . setAttribute ( 'hotkey' , '.' )
176
- this . setAttribute ( 'hotkey-requires-shift' , 'true' )
177
- }
178
162
}
179
163
180
164
if ( ! window . customElements . get ( 'md-quote' ) ) {
@@ -187,11 +171,6 @@ class MarkdownCodeButtonElement extends MarkdownButtonElement {
187
171
super ( )
188
172
styles . set ( this , { prefix : '`' , suffix : '`' , blockPrefix : '```' , blockSuffix : '```' } )
189
173
}
190
-
191
- connectedCallback ( ) {
192
- super . connectedCallback ( )
193
- this . setAttribute ( 'hotkey' , 'e' )
194
- }
195
174
}
196
175
197
176
if ( ! window . customElements . get ( 'md-code' ) ) {
@@ -204,11 +183,6 @@ class MarkdownLinkButtonElement extends MarkdownButtonElement {
204
183
super ( )
205
184
styles . set ( this , { prefix : '[' , suffix : '](url)' , replaceNext : 'url' , scanFor : 'https?://' } )
206
185
}
207
-
208
- connectedCallback ( ) {
209
- super . connectedCallback ( )
210
- this . setAttribute ( 'hotkey' , 'k' )
211
- }
212
186
}
213
187
214
188
if ( ! window . customElements . get ( 'md-link' ) ) {
@@ -233,11 +207,6 @@ class MarkdownUnorderedListButtonElement extends MarkdownButtonElement {
233
207
super ( )
234
208
styles . set ( this , { prefix : '- ' , multiline : true , surroundWithNewlines : true } )
235
209
}
236
- connectedCallback ( ) {
237
- super . connectedCallback ( )
238
- this . setAttribute ( 'hotkey' , '8' )
239
- this . setAttribute ( 'hotkey-requires-shift' , 'true' )
240
- }
241
210
}
242
211
243
212
if ( ! window . customElements . get ( 'md-unordered-list' ) ) {
@@ -250,11 +219,6 @@ class MarkdownOrderedListButtonElement extends MarkdownButtonElement {
250
219
super ( )
251
220
styles . set ( this , { prefix : '1. ' , multiline : true , orderedList : true } )
252
221
}
253
- connectedCallback ( ) {
254
- super . connectedCallback ( )
255
- this . setAttribute ( 'hotkey' , '7' )
256
- this . setAttribute ( 'hotkey-requires-shift' , 'true' )
257
- }
258
222
}
259
223
260
224
if ( ! window . customElements . get ( 'md-ordered-list' ) ) {
@@ -267,11 +231,6 @@ class MarkdownTaskListButtonElement extends MarkdownButtonElement {
267
231
super ( )
268
232
styles . set ( this , { prefix : '- [ ] ' , multiline : true , surroundWithNewlines : true } )
269
233
}
270
-
271
- connectedCallback ( ) {
272
- super . connectedCallback ( )
273
- this . setAttribute ( 'hotkey' , 'L' )
274
- }
275
234
}
276
235
277
236
if ( ! window . customElements . get ( 'md-task-list' ) ) {
@@ -315,8 +274,6 @@ if (!window.customElements.get('md-strikethrough')) {
315
274
window . customElements . define ( 'md-strikethrough' , MarkdownStrikethroughButtonElement )
316
275
}
317
276
318
- const modifierKey = navigator . userAgent . match ( / M a c i n t o s h / ) ? 'Meta' : 'Control'
319
-
320
277
class MarkdownToolbarElement extends HTMLElement {
321
278
constructor ( ) {
322
279
super ( )
@@ -327,21 +284,11 @@ class MarkdownToolbarElement extends HTMLElement {
327
284
this . setAttribute ( 'role' , 'toolbar' )
328
285
}
329
286
this . addEventListener ( 'keydown' , focusKeydown )
330
- const fn = shortcut . bind ( null , this )
331
- if ( this . field ) {
332
- this . field . addEventListener ( 'keydown' , fn )
333
- shortcutListeners . set ( this , fn )
334
- }
335
287
this . setAttribute ( 'tabindex' , '0' )
336
288
this . addEventListener ( 'focus' , onToolbarFocus , { once : true } )
337
289
}
338
290
339
291
disconnectedCallback ( ) : void {
340
- const fn = shortcutListeners . get ( this )
341
- if ( fn && this . field ) {
342
- this . field . removeEventListener ( 'keydown' , fn )
343
- shortcutListeners . delete ( this )
344
- }
345
292
this . removeEventListener ( 'keydown' , focusKeydown )
346
293
}
347
294
@@ -397,31 +344,6 @@ function focusKeydown(event: KeyboardEvent) {
397
344
buttons [ n ] . focus ( )
398
345
}
399
346
400
- const shortcutListeners = new WeakMap ( )
401
- function elementHotkeyRequiresShift ( element : Element ) : boolean {
402
- return element . hasAttribute ( 'hotkey-requires-shift' ) && element . getAttribute ( 'hotkey-requires-shift' ) !== 'false'
403
- }
404
-
405
- function findHotkey ( toolbar : Element , key : string , shiftPressed : boolean ) : HTMLElement | null {
406
- for ( const el of toolbar . querySelectorAll < HTMLElement > ( '[hotkey]' ) ) {
407
- if ( el . getAttribute ( 'hotkey' ) === key && ( ! elementHotkeyRequiresShift ( el ) || shiftPressed ) ) {
408
- return el
409
- }
410
- }
411
- return null
412
- }
413
-
414
- function shortcut ( toolbar : Element , event : KeyboardEvent ) {
415
- if ( ( event . metaKey && modifierKey === 'Meta' ) || ( event . ctrlKey && modifierKey === 'Control' ) ) {
416
- const key = event . shiftKey ? event . key . toUpperCase ( ) : event . key
417
- const button = findHotkey ( toolbar , key , event . shiftKey )
418
- if ( button ) {
419
- button . click ( )
420
- event . preventDefault ( )
421
- }
422
- }
423
- }
424
-
425
347
if ( ! window . customElements . get ( 'markdown-toolbar' ) ) {
426
348
window . MarkdownToolbarElement = MarkdownToolbarElement
427
349
window . customElements . define ( 'markdown-toolbar' , MarkdownToolbarElement )
0 commit comments