( cursor: number, delta: number, options: T[] )
| 1 | export function findCursor<T extends { disabled?: boolean }>( |
| 2 | cursor: number, |
| 3 | delta: number, |
| 4 | options: T[] |
| 5 | ) { |
| 6 | const hasEnabledOptions = options.some((opt) => !opt.disabled); |
| 7 | if (!hasEnabledOptions) { |
| 8 | return cursor; |
| 9 | } |
| 10 | const newCursor = cursor + delta; |
| 11 | const maxCursor = Math.max(options.length - 1, 0); |
| 12 | const clampedCursor = newCursor < 0 ? maxCursor : newCursor > maxCursor ? 0 : newCursor; |
| 13 | const newOption = options[clampedCursor]; |
| 14 | if (newOption.disabled) { |
| 15 | return findCursor(clampedCursor, delta < 0 ? -1 : 1, options); |
| 16 | } |
| 17 | return clampedCursor; |
| 18 | } |
| 19 | |
| 20 | export function findTextCursor( |
| 21 | cursor: number, |
no outgoing calls
no test coverage detected