(params: {
lineStarts: number[]
cursorPosition: number
desiredIndex: number
})
| 17 | } |
| 18 | |
| 19 | function cursorDown(params: { |
| 20 | lineStarts: number[] |
| 21 | cursorPosition: number |
| 22 | desiredIndex: number |
| 23 | }): number { |
| 24 | const { lineStarts, cursorPosition, desiredIndex } = params |
| 25 | const lineIndex = lineStarts.findLastIndex((start) => start <= cursorPosition) |
| 26 | |
| 27 | if (lineIndex === -1 || lineIndex === lineStarts.length - 1) { |
| 28 | return Infinity |
| 29 | } |
| 30 | |
| 31 | return Math.min( |
| 32 | (lineStarts[lineIndex + 2] ?? Infinity) - 1, |
| 33 | lineStarts[lineIndex + 1] + desiredIndex, |
| 34 | ) |
| 35 | } |
| 36 | |
| 37 | export function calculateNewCursorPosition(params: { |
| 38 | cursorPosition: number |
no outgoing calls
no test coverage detected