Skip to content

Commit 95b19a5

Browse files
committed
refactor: drop unecessary binding on focusKeydown
1 parent fa869bd commit 95b19a5

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

index.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,7 @@ class MarkdownToolbarElement extends HTMLElement {
225225
if (!this.hasAttribute('role')) {
226226
this.setAttribute('role', 'toolbar')
227227
}
228-
const focusKeydownfn = focusKeydown.bind(null, this)
229-
this.addEventListener('keydown', focusKeydownfn)
230-
focusListeners.set(this, focusKeydownfn)
228+
this.addEventListener('keydown', focusKeydown)
231229
const fn = shortcut.bind(null, this)
232230
if (this.field) {
233231
this.field.addEventListener('keydown', fn)
@@ -243,10 +241,7 @@ class MarkdownToolbarElement extends HTMLElement {
243241
this.field.removeEventListener('keydown', fn)
244242
shortcutListeners.delete(this)
245243
}
246-
const focusKeydownfn = focusListeners.get(this)
247-
if (focusKeydownfn) {
248-
this.removeEventListener('keydown', focusKeydownfn)
249-
}
244+
this.removeEventListener('keydown', focusKeydown)
250245
}
251246

252247
get field(): ?HTMLTextAreaElement {
@@ -257,15 +252,15 @@ class MarkdownToolbarElement extends HTMLElement {
257252
}
258253
}
259254

260-
const focusListeners = new WeakMap()
261-
262-
function focusKeydown(toolbar: MarkdownToolbarElement, event: KeyboardEvent) {
255+
function focusKeydown(event: KeyboardEvent) {
263256
const key = event.key
264257
if (key !== 'ArrowRight' && key !== 'ArrowLeft' && key !== 'Home' && key !== 'End') return
265258
const target = event.target
259+
const toolbar = event.currentTarget
266260
if (!(target instanceof HTMLElement)) return
261+
if (!(toolbar instanceof HTMLElement)) return
267262
if (!target.hasAttribute('data-md-button')) return
268-
if (target.closest('markdown-toolbar') !== event.currentTarget) return
263+
if (target.closest('markdown-toolbar') !== toolbar) return
269264

270265
const buttons = []
271266
for (const button of toolbar.querySelectorAll('[data-md-button]')) {

0 commit comments

Comments
 (0)