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

Function handler

packages/app-core/src/components/TasksView.tsx:281–404  ·  view source on GitHub ↗
(e: KeyboardEvent)

Source from the content-addressed store, hash-verified

279 useEffect(() => {
280 if (!isActivePanel) return
281 const handler = (e: KeyboardEvent): void => {
282 // A modal/menu owns the keyboard while open — don't fire list shortcuts
283 // through it. (songgenqing report)
284 if (isAppOverlayOpen()) return
285 // While the Vim hint overlay is open it owns the keyboard; don't let
286 // task navigation (or Esc closing the view) steal its keys. (#151)
287 if (document.querySelector('[data-vim-hint-overlay]')) return
288 const active = document.activeElement as HTMLElement | null
289 if (active) {
290 const tag = active.tagName
291 if (tag === 'INPUT' || tag === 'TEXTAREA' || active.isContentEditable) return
292 }
293 if (e.metaKey || e.ctrlKey || e.altKey) return
294
295 const key = e.key
296 const overrides = keymapOverrides
297 // When Vim mode is off, the single-key Vim shortcuts (j/k/gg/G/o/Space/1-3/…)
298 // are disabled — only arrows/Enter/Escape navigate. (songgenqing report)
299 const seq = (id: Parameters<typeof matchesSequenceToken>[2]): boolean =>
300 vimMode && matchesSequenceToken(e, overrides, id)
301 const consume = (): void => {
302 e.preventDefault()
303 e.stopImmediatePropagation()
304 }
305
306 if (key === 'Escape') {
307 // Tasks is a tab like a note tab — Esc clears an active filter but must
308 // never close the tab (other tabs don't close on Esc). Close with :q,
309 // the header ✕, or ⌘W. (#151)
310 consume()
311 if (filter) setFilter('')
312 return
313 }
314
315 // View switcher works regardless of sub-view (Vim mode only).
316 if (vimMode && key === '1') {
317 consume()
318 setViewMode('list')
319 return
320 }
321 if (vimMode && key === '2') {
322 consume()
323 setViewMode('calendar')
324 return
325 }
326 if (vimMode && key === '3') {
327 consume()
328 setViewMode('kanban')
329 return
330 }
331
332 if (seq('nav.filter')) {
333 consume()
334 filterRef.current?.focus()
335 filterRef.current?.select()
336 return
337 }
338

Callers

nothing calls this directly

Calls 6

isAppOverlayOpenFunction · 0.90
matchesSequenceTokenFunction · 0.90
advanceSequenceFunction · 0.90
getKeymapBindingFunction · 0.90
consumeFunction · 0.70
seqFunction · 0.70

Tested by

no test coverage detected