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