@@ -135,11 +135,6 @@ class MarkdownBoldButtonElement extends MarkdownButtonElement {
135135 super ( )
136136 styles . set ( this , { prefix : '**' , suffix : '**' , trimFirst : true } )
137137 }
138-
139- connectedCallback ( ) {
140- super . connectedCallback ( )
141- this . setAttribute ( 'hotkey' , 'b' )
142- }
143138}
144139
145140if ( ! window . customElements . get ( 'md-bold' ) ) {
@@ -152,11 +147,6 @@ class MarkdownItalicButtonElement extends MarkdownButtonElement {
152147 super ( )
153148 styles . set ( this , { prefix : '_' , suffix : '_' , trimFirst : true } )
154149 }
155-
156- connectedCallback ( ) {
157- super . connectedCallback ( )
158- this . setAttribute ( 'hotkey' , 'i' )
159- }
160150}
161151
162152if ( ! window . customElements . get ( 'md-italic' ) ) {
@@ -169,12 +159,6 @@ class MarkdownQuoteButtonElement extends MarkdownButtonElement {
169159 super ( )
170160 styles . set ( this , { prefix : '> ' , multiline : true , surroundWithNewlines : true } )
171161 }
172-
173- connectedCallback ( ) {
174- super . connectedCallback ( )
175- this . setAttribute ( 'hotkey' , '.' )
176- this . setAttribute ( 'hotkey-requires-shift' , 'true' )
177- }
178162}
179163
180164if ( ! window . customElements . get ( 'md-quote' ) ) {
@@ -187,11 +171,6 @@ class MarkdownCodeButtonElement extends MarkdownButtonElement {
187171 super ( )
188172 styles . set ( this , { prefix : '`' , suffix : '`' , blockPrefix : '```' , blockSuffix : '```' } )
189173 }
190-
191- connectedCallback ( ) {
192- super . connectedCallback ( )
193- this . setAttribute ( 'hotkey' , 'e' )
194- }
195174}
196175
197176if ( ! window . customElements . get ( 'md-code' ) ) {
@@ -204,11 +183,6 @@ class MarkdownLinkButtonElement extends MarkdownButtonElement {
204183 super ( )
205184 styles . set ( this , { prefix : '[' , suffix : '](url)' , replaceNext : 'url' , scanFor : 'https?://' } )
206185 }
207-
208- connectedCallback ( ) {
209- super . connectedCallback ( )
210- this . setAttribute ( 'hotkey' , 'k' )
211- }
212186}
213187
214188if ( ! window . customElements . get ( 'md-link' ) ) {
@@ -233,11 +207,6 @@ class MarkdownUnorderedListButtonElement extends MarkdownButtonElement {
233207 super ( )
234208 styles . set ( this , { prefix : '- ' , multiline : true , surroundWithNewlines : true } )
235209 }
236- connectedCallback ( ) {
237- super . connectedCallback ( )
238- this . setAttribute ( 'hotkey' , '8' )
239- this . setAttribute ( 'hotkey-requires-shift' , 'true' )
240- }
241210}
242211
243212if ( ! window . customElements . get ( 'md-unordered-list' ) ) {
@@ -250,11 +219,6 @@ class MarkdownOrderedListButtonElement extends MarkdownButtonElement {
250219 super ( )
251220 styles . set ( this , { prefix : '1. ' , multiline : true , orderedList : true } )
252221 }
253- connectedCallback ( ) {
254- super . connectedCallback ( )
255- this . setAttribute ( 'hotkey' , '7' )
256- this . setAttribute ( 'hotkey-requires-shift' , 'true' )
257- }
258222}
259223
260224if ( ! window . customElements . get ( 'md-ordered-list' ) ) {
@@ -267,11 +231,6 @@ class MarkdownTaskListButtonElement extends MarkdownButtonElement {
267231 super ( )
268232 styles . set ( this , { prefix : '- [ ] ' , multiline : true , surroundWithNewlines : true } )
269233 }
270-
271- connectedCallback ( ) {
272- super . connectedCallback ( )
273- this . setAttribute ( 'hotkey' , 'L' )
274- }
275234}
276235
277236if ( ! window . customElements . get ( 'md-task-list' ) ) {
@@ -315,8 +274,6 @@ if (!window.customElements.get('md-strikethrough')) {
315274 window . customElements . define ( 'md-strikethrough' , MarkdownStrikethroughButtonElement )
316275}
317276
318- const modifierKey = navigator . userAgent . match ( / M a c i n t o s h / ) ? 'Meta' : 'Control'
319-
320277class MarkdownToolbarElement extends HTMLElement {
321278 constructor ( ) {
322279 super ( )
@@ -327,21 +284,11 @@ class MarkdownToolbarElement extends HTMLElement {
327284 this . setAttribute ( 'role' , 'toolbar' )
328285 }
329286 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- }
335287 this . setAttribute ( 'tabindex' , '0' )
336288 this . addEventListener ( 'focus' , onToolbarFocus , { once : true } )
337289 }
338290
339291 disconnectedCallback ( ) : void {
340- const fn = shortcutListeners . get ( this )
341- if ( fn && this . field ) {
342- this . field . removeEventListener ( 'keydown' , fn )
343- shortcutListeners . delete ( this )
344- }
345292 this . removeEventListener ( 'keydown' , focusKeydown )
346293 }
347294
@@ -397,31 +344,6 @@ function focusKeydown(event: KeyboardEvent) {
397344 buttons [ n ] . focus ( )
398345}
399346
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-
425347if ( ! window . customElements . get ( 'markdown-toolbar' ) ) {
426348 window . MarkdownToolbarElement = MarkdownToolbarElement
427349 window . customElements . define ( 'markdown-toolbar' , MarkdownToolbarElement )
0 commit comments