(params: {
lineStarts: number[]
cursorPosition: number
desiredIndex: number
})
| 1 | function cursorUp(params: { |
| 2 | lineStarts: number[] |
| 3 | cursorPosition: number |
| 4 | desiredIndex: number |
| 5 | }): number { |
| 6 | const { lineStarts, cursorPosition, desiredIndex } = params |
| 7 | const lineIndex = lineStarts.findLastIndex((start) => start <= cursorPosition) |
| 8 | |
| 9 | if (lineIndex === -1 || lineIndex === 0) { |
| 10 | return 0 |
| 11 | } |
| 12 | |
| 13 | const prevLineStart = lineStarts[lineIndex - 1] |
| 14 | const prevLineEndExclusive = lineStarts[lineIndex] - 1 |
| 15 | |
| 16 | return Math.min(prevLineEndExclusive, prevLineStart + desiredIndex) |
| 17 | } |
| 18 | |
| 19 | function cursorDown(params: { |
| 20 | lineStarts: number[] |
no outgoing calls
no test coverage detected