* Convert Ace position {row, column} to CodeMirror offset
(pos, doc)
| 41 | * Convert Ace position {row, column} to CodeMirror offset |
| 42 | */ |
| 43 | function positionToOffset(pos, doc) { |
| 44 | if (!pos || !doc) return 0; |
| 45 | try { |
| 46 | const lineNum = Math.max(1, Math.min((pos.row ?? 0) + 1, doc.lines)); |
| 47 | const line = doc.line(lineNum); |
| 48 | const col = Math.max(0, Math.min(pos.column ?? 0, line.length)); |
| 49 | return line.from + col; |
| 50 | } catch (_) { |
| 51 | return 0; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Convert CodeMirror offset to Ace position {row, column} |