(e: KeyboardEvent, state: ReturnType<typeof useStore.getState>)
| 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 ( |
no test coverage detected