* Get the line number for a character index
(index: number)
| 517 | * Get the line number for a character index |
| 518 | */ |
| 519 | private getLineNumber(index: number): number { |
| 520 | // The line starts at or before the index: one more than the newlines before it. |
| 521 | const starts = this.lineStarts(); |
| 522 | if (!(index > 0)) return 1; |
| 523 | let low = 0; |
| 524 | let high = starts.length; |
| 525 | while (low < high) { |
| 526 | const mid = (low + high) >> 1; |
| 527 | if (starts[mid]! <= index) low = mid + 1; |
| 528 | else high = mid; |
| 529 | } |
| 530 | return low; |
| 531 | } |
| 532 | |
| 533 | /** |
| 534 | * Get the character index of the start of a line |
no test coverage detected