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

Function handler

packages/app-core/src/components/ArchiveView.tsx:276–365  ·  view source on GitHub ↗
(e: KeyboardEvent)

Source from the content-addressed store, hash-verified

274 useEffect(() => {
275 if (!amActive) return
276 const handler = (e: KeyboardEvent): void => {
277 // A modal/menu owns the keyboard while open — don't fire list shortcuts
278 // through it. (songgenqing report)
279 if (isAppOverlayOpen()) return
280 const active = document.activeElement as HTMLElement | null
281 if (active) {
282 const tag = active.tagName
283 if (tag === 'INPUT' || tag === 'TEXTAREA' || active.isContentEditable) return
284 }
285 if (e.metaKey || e.ctrlKey || e.altKey) return
286
287 const key = e.key
288 const overrides = keymapOverrides
289 // When Vim mode is off, the single-key Vim shortcuts (j/k/x/d/gg/G/o/r//…)
290 // are disabled — only arrows/Enter/Escape navigate. (songgenqing report)
291 const seq = (id: Parameters<typeof matchesSequenceToken>[2]): boolean =>
292 vimMode && matchesSequenceToken(e, overrides, id)
293 const consume = (): void => {
294 e.preventDefault()
295 e.stopImmediatePropagation()
296 }
297
298 if (key === 'Escape') {
299 if (filter) {
300 consume()
301 setFilter('')
302 return
303 }
304 consume()
305 void closeActiveNote()
306 return
307 }
308
309 if (seq('nav.filter')) {
310 consume()
311 filterRef.current?.focus()
312 filterRef.current?.select()
313 return
314 }
315
316 if (seq('nav.contextMenu') && current) {
317 consume()
318 openMenuForCurrent()
319 return
320 }
321
322 if (seq('nav.moveDown') || key === 'ArrowDown') {
323 consume()
324 setCursorIndex((i) => Math.max(0, Math.min(filtered.length - 1, i + 1)))
325 return
326 }
327 if (seq('nav.moveUp') || key === 'ArrowUp') {
328 consume()
329 setCursorIndex((i) => Math.max(0, Math.min(filtered.length - 1, i - 1)))
330 return
331 }
332 if (seq('nav.jumpBottom')) {
333 consume()

Callers

nothing calls this directly

Calls 7

isAppOverlayOpenFunction · 0.90
advanceSequenceFunction · 0.90
getKeymapBindingFunction · 0.90
moveNoteToTrashFunction · 0.85
consumeFunction · 0.70
seqFunction · 0.70
unarchiveNoteFunction · 0.50

Tested by

no test coverage detected