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

Function handleNoteListKey

packages/app-core/src/components/VimNav.tsx:1153–1262  ·  view source on GitHub ↗
(e: KeyboardEvent, state: ReturnType<typeof useStore.getState>)

Source from the content-addressed store, hash-verified

1151 }
1152
1153 function handleNoteListKey(e: KeyboardEvent, state: ReturnType<typeof useStore.getState>): void {
1154 const key = e.key
1155 const overrides = state.keymapOverrides
1156 const items = getIndexedElements('[data-notelist-idx]', 'notelistIdx')
1157 const count = getNoteListItemCount(items.length)
1158 const max = count - 1
1159 const currentIndex = clampIndex(state.noteListCursorIndex, count)
1160 const wantsContextMenu =
1161 matchesSequenceToken(e, overrides, 'nav.contextMenu') ||
1162 wantsNativeContextMenuKey(e)
1163
1164 const wantsHandledKey =
1165 matchesSequenceToken(e, overrides, 'nav.moveDown') ||
1166 matchesSequenceToken(e, overrides, 'nav.moveUp') ||
1167 matchesSequenceToken(e, overrides, 'nav.jumpBottom') ||
1168 sequenceTokenFromEvent(e) === getSequenceTokens(overrides, 'nav.jumpTop')[0] ||
1169 matchesSequenceToken(e, overrides, 'nav.openSideItem') ||
1170 matchesSequenceToken(e, overrides, 'nav.back') ||
1171 matchesSequenceToken(e, overrides, 'nav.filter') ||
1172 key === 'Enter' ||
1173 key === 'Escape' ||
1174 key === 'ArrowDown' ||
1175 key === 'ArrowUp' ||
1176 key === 'ArrowLeft' ||
1177 key === 'ArrowRight' ||
1178 wantsContextMenu
1179 if (wantsHandledKey) {
1180 e.preventDefault()
1181 e.stopImmediatePropagation()
1182 } else {
1183 return
1184 }
1185
1186 if (count === 0) return
1187
1188 if (matchesSequenceToken(e, overrides, 'nav.moveDown') || key === 'ArrowDown') {
1189 scrollToIndexedIndex(
1190 items,
1191 'notelistIdx',
1192 moveIndex(currentIndex, count, 1),
1193 state.setNoteListCursorIndex
1194 )
1195 return
1196 }
1197 if (matchesSequenceToken(e, overrides, 'nav.moveUp') || key === 'ArrowUp') {
1198 scrollToIndexedIndex(
1199 items,
1200 'notelistIdx',
1201 moveIndex(currentIndex, count, -1),
1202 state.setNoteListCursorIndex
1203 )
1204 return
1205 }
1206 if (matchesSequenceToken(e, overrides, 'nav.jumpBottom')) {
1207 scrollToIndexedIndex(items, 'notelistIdx', max, state.setNoteListCursorIndex)
1208 return
1209 }
1210 if (

Callers 1

handlerFunction · 0.85

Calls 13

clampIndexFunction · 0.90
matchesSequenceTokenFunction · 0.90
sequenceTokenFromEventFunction · 0.90
getSequenceTokensFunction · 0.90
moveIndexFunction · 0.90
advanceSequenceFunction · 0.90
getKeymapBindingFunction · 0.90
getIndexedElementsFunction · 0.85
getNoteListItemCountFunction · 0.85
scrollToIndexedIndexFunction · 0.85
getIndexedElementByIndexFunction · 0.85

Tested by

no test coverage detected