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

Function handler

packages/app-core/src/components/QuickNotesView.tsx:101–180  ·  view source on GitHub ↗
(e: KeyboardEvent)

Source from the content-addressed store, hash-verified

99 useEffect(() => {
100 if (!amActive) return
101 const handler = (e: KeyboardEvent): void => {
102 // A modal/menu owns the keyboard while open — don't fire list shortcuts
103 // through it. (songgenqing report)
104 if (isAppOverlayOpen()) return
105 const active = document.activeElement as HTMLElement | null
106 if (active) {
107 const tag = active.tagName
108 if (tag === 'INPUT' || tag === 'TEXTAREA' || active.isContentEditable) return
109 }
110 if (e.metaKey || e.ctrlKey || e.altKey) return
111
112 const key = e.key
113 const overrides = keymapOverrides
114 // When Vim mode is off, the single-key Vim shortcuts (j/k/gg/G/o//…) are
115 // disabled — only arrows/Enter/Escape navigate. (songgenqing report)
116 const seq = (id: Parameters<typeof matchesSequenceToken>[2]): boolean =>
117 vimMode && matchesSequenceToken(e, overrides, id)
118 const consume = (): void => {
119 e.preventDefault()
120 e.stopImmediatePropagation()
121 }
122
123 if (key === 'Escape') {
124 if (filter) {
125 consume()
126 setFilter('')
127 return
128 }
129 consume()
130 void closeActiveNote()
131 return
132 }
133
134 if (seq('nav.filter')) {
135 consume()
136 filterRef.current?.focus()
137 filterRef.current?.select()
138 return
139 }
140
141 if (seq('nav.newQuickNote')) {
142 consume()
143 void createQuickNote()
144 return
145 }
146
147 if (seq('nav.moveDown') || key === 'ArrowDown') {
148 consume()
149 setCursorIndex((i) => Math.max(0, Math.min(filtered.length - 1, i + 1)))
150 return
151 }
152 if (seq('nav.moveUp') || key === 'ArrowUp') {
153 consume()
154 setCursorIndex((i) => Math.max(0, Math.min(filtered.length - 1, i - 1)))
155 return
156 }
157 if (seq('nav.jumpBottom')) {
158 consume()

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected