( lines: string[], row: number, col: number, )
| 649 | * Inverse operation of offsetToLogicalPos |
| 650 | */ |
| 651 | export function logicalPosToOffset( |
| 652 | lines: string[], |
| 653 | row: number, |
| 654 | col: number, |
| 655 | ): number { |
| 656 | let offset = 0; |
| 657 | |
| 658 | // Clamp row to valid range |
| 659 | const actualRow = Math.min(row, lines.length - 1); |
| 660 | |
| 661 | // Add lengths of all lines before the target row |
| 662 | for (let i = 0; i < actualRow; i++) { |
| 663 | offset += cpLen(lines[i]) + 1; // +1 for newline |
| 664 | } |
| 665 | |
| 666 | // Add column offset within the target row |
| 667 | if (actualRow >= 0 && actualRow < lines.length) { |
| 668 | offset += Math.min(col, cpLen(lines[actualRow])); |
| 669 | } |
| 670 | |
| 671 | return offset; |
| 672 | } |
| 673 | |
| 674 | // Helper to calculate visual lines and map cursor positions |
| 675 | function calculateVisualLayout( |
no test coverage detected