Skip to content

Commit 8e9a9a8

Browse files
koddssonkhiga8bolonio
committed
Remove hotkey functionality
Co-authored-by: Kate Higa <[email protected]> Co-authored-by: Adrián Bolonio <[email protected]>
1 parent 053df7b commit 8e9a9a8

File tree

1 file changed

+0
-37
lines changed

1 file changed

+0
-37
lines changed

src/index.ts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,6 @@ if (!window.customElements.get('md-strikethrough')) {
274274
window.customElements.define('md-strikethrough', MarkdownStrikethroughButtonElement)
275275
}
276276

277-
const modifierKey = navigator.userAgent.match(/Macintosh/) ? 'Meta' : 'Control'
278-
279277
class MarkdownToolbarElement extends HTMLElement {
280278
constructor() {
281279
super()
@@ -286,21 +284,11 @@ class MarkdownToolbarElement extends HTMLElement {
286284
this.setAttribute('role', 'toolbar')
287285
}
288286
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-
}
294287
this.setAttribute('tabindex', '0')
295288
this.addEventListener('focus', onToolbarFocus, {once: true})
296289
}
297290

298291
disconnectedCallback(): void {
299-
const fn = shortcutListeners.get(this)
300-
if (fn && this.field) {
301-
this.field.removeEventListener('keydown', fn)
302-
shortcutListeners.delete(this)
303-
}
304292
this.removeEventListener('keydown', focusKeydown)
305293
}
306294

@@ -356,31 +344,6 @@ function focusKeydown(event: KeyboardEvent) {
356344
buttons[n].focus()
357345
}
358346

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-
384347
if (!window.customElements.get('markdown-toolbar')) {
385348
window.MarkdownToolbarElement = MarkdownToolbarElement
386349
window.customElements.define('markdown-toolbar', MarkdownToolbarElement)

0 commit comments

Comments
 (0)