Resolve the next keyboard action and logical position for one hunk-per-file navigation.
( position: number, direction: number, options: CliOptions, )
| 180 | |
| 181 | /** Resolve the next keyboard action and logical position for one hunk-per-file navigation. */ |
| 182 | function nextNavigationKey( |
| 183 | position: number, |
| 184 | direction: number, |
| 185 | options: CliOptions, |
| 186 | ): { key: "]" | "["; position: number; direction: number } { |
| 187 | if (options.mode === "forward") { |
| 188 | return { key: "]", position: Math.min(options.fileCount - 1, position + 1), direction: 1 }; |
| 189 | } |
| 190 | |
| 191 | let nextDirection = direction; |
| 192 | if (position >= options.fileCount - 1) { |
| 193 | nextDirection = -1; |
| 194 | } else if (position <= 0) { |
| 195 | nextDirection = 1; |
| 196 | } |
| 197 | |
| 198 | return { |
| 199 | key: nextDirection > 0 ? "]" : "[", |
| 200 | position: Math.max(0, Math.min(options.fileCount - 1, position + nextDirection)), |
| 201 | direction: nextDirection, |
| 202 | }; |
| 203 | } |
| 204 | |
| 205 | async function renderOnce(setup: Awaited<ReturnType<typeof testRender>>) { |
| 206 | await act(async () => { |