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

Function handler

packages/app-core/src/components/TrashView.tsx:129–212  ·  view source on GitHub ↗
(e: KeyboardEvent)

Source from the content-addressed store, hash-verified

127 useEffect(() => {
128 if (!amActive) return
129 const handler = (e: KeyboardEvent): void => {
130 // A modal/menu (e.g. the delete-confirm dialog) owns the keyboard while
131 // open — don't let list shortcuts fire through it. (songgenqing report)
132 if (isAppOverlayOpen()) return
133 const active = document.activeElement as HTMLElement | null
134 if (active) {
135 const tag = active.tagName
136 if (tag === 'INPUT' || tag === 'TEXTAREA' || active.isContentEditable) return
137 }
138 if (e.metaKey || e.ctrlKey || e.altKey) return
139
140 const key = e.key
141 const overrides = keymapOverrides
142 // When Vim mode is off, the single-key Vim shortcuts (j/k/x/d/gg/G/o/r//…)
143 // are disabled — only arrows/Enter/Escape navigate. (songgenqing report)
144 const seq = (id: Parameters<typeof matchesSequenceToken>[2]): boolean =>
145 vimMode && matchesSequenceToken(e, overrides, id)
146 const consume = (): void => {
147 e.preventDefault()
148 e.stopImmediatePropagation()
149 }
150
151 if (key === 'Escape') {
152 if (filter) {
153 consume()
154 setFilter('')
155 return
156 }
157 consume()
158 void closeActiveNote()
159 return
160 }
161
162 if (seq('nav.filter')) {
163 consume()
164 filterRef.current?.focus()
165 filterRef.current?.select()
166 return
167 }
168
169 if (seq('nav.moveDown') || key === 'ArrowDown') {
170 consume()
171 setCursorIndex((i) => Math.max(0, Math.min(filtered.length - 1, i + 1)))
172 return
173 }
174 if (seq('nav.moveUp') || key === 'ArrowUp') {
175 consume()
176 setCursorIndex((i) => Math.max(0, Math.min(filtered.length - 1, i - 1)))
177 return
178 }
179 if (seq('nav.jumpBottom')) {
180 consume()
181 setCursorIndex(filtered.length - 1)
182 return
183 }
184 if (
185 vimMode &&
186 advanceSequence(

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