Skip to content

Commit 98ed87f

Browse files
committed
refactor: DRY up indexOf calls
1 parent 054b4c3 commit 98ed87f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,15 @@ class MarkdownToolbarElement extends HTMLElement {
274274
function focusKeydown(event: KeyboardEvent) {
275275
const key = event.key
276276
if (key !== 'ArrowRight' && key !== 'ArrowLeft' && key !== 'Home' && key !== 'End') return
277-
const target = event.target
278277
const toolbar = event.currentTarget
279278
if (!(toolbar instanceof HTMLElement)) return
280279
const buttons = getButtons(toolbar)
281-
if (buttons.indexOf(event.target) === -1) return
280+
const index = buttons.indexOf(event.target)
281+
if (index === -1) return
282282

283283
let n = 0
284-
if (key === 'ArrowLeft') n = buttons.indexOf(target) - 1
285-
if (key === 'ArrowRight') n = buttons.indexOf(target) + 1
284+
if (key === 'ArrowLeft') n = index - 1
285+
if (key === 'ArrowRight') n = index + 1
286286
if (key === 'End') n = buttons.length - 1
287287
if (n < 0) n = buttons.length - 1
288288
if (n > buttons.length - 1) n = 0

0 commit comments

Comments
 (0)