MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / handleCommentsKey

Function handleCommentsKey

packages/app-core/src/components/VimNav.tsx:1358–1467  ·  view source on GitHub ↗
(e: KeyboardEvent, state: ReturnType<typeof useStore.getState>)

Source from the content-addressed store, hash-verified

1356 }
1357
1358 function handleCommentsKey(e: KeyboardEvent, state: ReturnType<typeof useStore.getState>): void {
1359 const key = e.key
1360 const overrides = state.keymapOverrides
1361 const target = e.target instanceof HTMLElement ? e.target : null
1362 const nativeButtonActivation =
1363 !!target?.closest('[data-comment-card-control]') &&
1364 (key === 'Enter' || key === ' ')
1365 if (nativeButtonActivation) return
1366
1367 const items = getCommentItems()
1368 const count = items.length
1369 const max = count - 1
1370 const currentPos = findCommentPosition(items, state.activeCommentId)
1371 const wantsHandledKey =
1372 matchesSequenceToken(e, overrides, 'nav.moveDown') ||
1373 matchesSequenceToken(e, overrides, 'nav.moveUp') ||
1374 matchesSequenceToken(e, overrides, 'nav.jumpBottom') ||
1375 sequenceTokenFromEvent(e) === getSequenceTokens(overrides, 'nav.jumpTop')[0] ||
1376 matchesSequenceToken(e, overrides, 'nav.openSideItem') ||
1377 matchesSequenceToken(e, overrides, 'nav.back') ||
1378 matchesSequenceToken(e, overrides, 'nav.filter') ||
1379 key === 'Enter' ||
1380 key === 'o' ||
1381 key === 'e' ||
1382 key === 'r' ||
1383 key === 'd' ||
1384 key === 'n' ||
1385 key === '+' ||
1386 key === 'Backspace' ||
1387 key === 'Delete' ||
1388 key === 'Escape' ||
1389 key === 'ArrowDown' ||
1390 key === 'ArrowUp' ||
1391 key === 'ArrowLeft' ||
1392 key === 'ArrowRight'
1393 if (!wantsHandledKey) return
1394
1395 e.preventDefault()
1396 e.stopImmediatePropagation()
1397 if (state.focusedPanel !== 'comments') state.setFocusedPanel('comments')
1398 document.querySelector<HTMLElement>('[data-comments-panel]')?.focus({ preventScroll: true })
1399
1400 if (key === 'Escape' || matchesSequenceToken(e, overrides, 'nav.back') || key === 'ArrowLeft') {
1401 focusEditor()
1402 return
1403 }
1404 if (key === 'n' || key === '+') {
1405 document.querySelector<HTMLElement>('[data-comments-new]')?.click()
1406 return
1407 }
1408 if (matchesSequenceToken(e, overrides, 'nav.filter')) {
1409 state.setSearchOpen(true)
1410 return
1411 }
1412
1413 if (count === 0) return
1414
1415 if (matchesSequenceToken(e, overrides, 'nav.moveDown') || key === 'ArrowDown') {

Callers 1

handlerFunction · 0.85

Calls 10

matchesSequenceTokenFunction · 0.90
sequenceTokenFromEventFunction · 0.90
getSequenceTokensFunction · 0.90
advanceSequenceFunction · 0.90
getKeymapBindingFunction · 0.90
getCommentItemsFunction · 0.85
findCommentPositionFunction · 0.85
scrollToCommentElementFunction · 0.85
activateCommentItemFunction · 0.85
clickCommentActionFunction · 0.85

Tested by

no test coverage detected