| 118 | } |
| 119 | |
| 120 | function findQuoteObject( |
| 121 | text: string, |
| 122 | offset: number, |
| 123 | quote: string, |
| 124 | isInner: boolean, |
| 125 | ): TextObjectRange { |
| 126 | const lineStart = text.lastIndexOf('\n', offset - 1) + 1 |
| 127 | const lineEnd = text.indexOf('\n', offset) |
| 128 | const effectiveEnd = lineEnd === -1 ? text.length : lineEnd |
| 129 | const line = text.slice(lineStart, effectiveEnd) |
| 130 | const posInLine = offset - lineStart |
| 131 | |
| 132 | const positions: number[] = [] |
| 133 | for (let i = 0; i < line.length; i++) { |
| 134 | if (line[i] === quote) positions.push(i) |
| 135 | } |
| 136 | |
| 137 | // Pair quotes correctly: 0-1, 2-3, 4-5, etc. |
| 138 | for (let i = 0; i < positions.length - 1; i += 2) { |
| 139 | const qs = positions[i]! |
| 140 | const qe = positions[i + 1]! |
| 141 | if (qs <= posInLine && posInLine <= qe) { |
| 142 | return isInner |
| 143 | ? { start: lineStart + qs + 1, end: lineStart + qe } |
| 144 | : { start: lineStart + qs, end: lineStart + qe + 1 } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | return null |
| 149 | } |
| 150 | |
| 151 | function findBracketObject( |
| 152 | text: string, |