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

Function handler

packages/app-core/src/components/TasksCalendar.tsx:362–568  ·  view source on GitHub ↗
(e: KeyboardEvent)

Source from the content-addressed store, hash-verified

360 // sidebar bindings (same trick TasksView's list mode uses).
361 useEffect(() => {
362 const handler = (e: KeyboardEvent): void => {
363 // While the Vim hint overlay is open it owns the keyboard; yield to it. (#151)
364 if (document.querySelector('[data-vim-hint-overlay]')) return
365 const active = document.activeElement as HTMLElement | null
366 if (active) {
367 const tag = active.tagName
368 if (tag === 'INPUT' || tag === 'TEXTAREA' || active.isContentEditable) return
369 }
370
371 const consume = (): void => {
372 e.preventDefault()
373 e.stopImmediatePropagation()
374 }
375
376 if (e.metaKey || e.ctrlKey || e.altKey) return
377
378 // Grab & place: while a task is picked up, the grid navigation chooses a
379 // target day; Enter places it (move / set-due choice), Esc cancels.
380 if (grabbedTask) {
381 if (e.key === 'Escape') {
382 consume()
383 setGrabbedTask(null)
384 return
385 }
386 if (e.key === 'Enter') {
387 consume()
388 const cell = document.querySelector(`[data-cal-day="${selectedIso}"]`)
389 const rect = cell?.getBoundingClientRect()
390 setMenu({
391 x: rect ? rect.left + rect.width / 2 : window.innerWidth / 2,
392 y: rect ? rect.bottom : window.innerHeight / 2,
393 items: dropChoiceItems(grabbedTask, selectedIso, onMoveTask, onRescheduleTask)
394 })
395 setGrabbedTask(null)
396 return
397 }
398 switch (e.key) {
399 case 'h':
400 case 'ArrowLeft':
401 consume()
402 moveSelection(-1)
403 return
404 case 'l':
405 case 'ArrowRight':
406 consume()
407 moveSelection(1)
408 return
409 case 'j':
410 case 'ArrowDown':
411 consume()
412 moveSelection(7)
413 return
414 case 'k':
415 case 'ArrowUp':
416 consume()
417 moveSelection(-7)
418 return
419 case '[':

Callers

nothing calls this directly

Calls 9

toIsoDateLocalFunction · 0.90
dropChoiceItemsFunction · 0.85
moveSelectionFunction · 0.85
goToMonthFunction · 0.85
goToTodayFunction · 0.85
firstOfMonthFunction · 0.85
addDaysFunction · 0.85
consumeFunction · 0.70
taskTailFunction · 0.70

Tested by

no test coverage detected