|
126 | 126 |
|
127 | 127 | // Maps a position in a case-folded line back to a position in the original line |
128 | 128 | // (compensating for codepoints increasing in number during folding) |
129 | | - function adjustPos(orig, folded, pos) { |
| 129 | + function adjustPos(orig, folded, pos, foldFunc) { |
130 | 130 | if (orig.length == folded.length) return pos |
131 | 131 | for (var pos1 = Math.min(pos, orig.length);;) { |
132 | | - var len1 = doFold(orig.slice(0, pos1)).length |
| 132 | + var len1 = foldFunc(orig.slice(0, pos1)).length |
133 | 133 | if (len1 < pos) ++pos1 |
134 | 134 | else if (len1 > pos) --pos1 |
135 | 135 | else return pos1 |
|
148 | 148 | if (lines.length == 1) { |
149 | 149 | var found = string.indexOf(lines[0]) |
150 | 150 | if (found == -1) continue search |
151 | | - var start = adjustPos(orig, string, found) + ch |
152 | | - return {from: Pos(line, adjustPos(orig, string, found) + ch), |
153 | | - to: Pos(line, adjustPos(orig, string, found + lines[0].length) + ch)} |
| 151 | + var start = adjustPos(orig, string, found, fold) + ch |
| 152 | + return {from: Pos(line, adjustPos(orig, string, found, fold) + ch), |
| 153 | + to: Pos(line, adjustPos(orig, string, found + lines[0].length, fold) + ch)} |
154 | 154 | } else { |
155 | 155 | var cutFrom = string.length - lines[0].length |
156 | 156 | if (string.slice(cutFrom) != lines[0]) continue search |
157 | 157 | for (var i = 1; i < lines.length - 1; i++) |
158 | 158 | if (fold(doc.getLine(line + i)) != lines[i]) continue search |
159 | 159 | var end = doc.getLine(line + lines.length - 1), endString = fold(end), lastLine = lines[lines.length - 1] |
160 | 160 | if (end.slice(0, lastLine.length) != lastLine) continue search |
161 | | - return {from: Pos(line, adjustPos(orig, string, cutFrom) + ch), |
162 | | - to: Pos(line + lines.length - 1, adjustPos(end, endString, lastLine.length))} |
| 161 | + return {from: Pos(line, adjustPos(orig, string, cutFrom, fold) + ch), |
| 162 | + to: Pos(line + lines.length - 1, adjustPos(end, endString, lastLine.length, fold))} |
163 | 163 | } |
164 | 164 | } |
165 | 165 | } |
|
176 | 176 | if (lines.length == 1) { |
177 | 177 | var found = string.lastIndexOf(lines[0]) |
178 | 178 | if (found == -1) continue search |
179 | | - return {from: Pos(line, adjustPos(orig, string, found)), |
180 | | - to: Pos(line, adjustPos(orig, string, found + lines[0].length))} |
| 179 | + return {from: Pos(line, adjustPos(orig, string, found, fold)), |
| 180 | + to: Pos(line, adjustPos(orig, string, found + lines[0].length, fold))} |
181 | 181 | } else { |
182 | 182 | var lastLine = lines[lines.length - 1] |
183 | 183 | if (string.slice(0, lastLine.length) != lastLine) continue search |
184 | 184 | for (var i = 1, start = line - lines.length + 1; i < lines.length - 1; i++) |
185 | 185 | if (fold(doc.getLine(start + i)) != lines[i]) continue search |
186 | 186 | var top = doc.getLine(line + 1 - lines.length), topString = fold(top) |
187 | 187 | if (topString.slice(topString.length - lines[0].length) != lines[0]) continue search |
188 | | - return {from: Pos(line + 1 - lines.length, adjustPos(top, topString, top.length - lines[0].length)), |
189 | | - to: Pos(line, adjustPos(orig, string, lastLine.length))} |
| 188 | + return {from: Pos(line + 1 - lines.length, adjustPos(top, topString, top.length - lines[0].length, fold)), |
| 189 | + to: Pos(line, adjustPos(orig, string, lastLine.length, fold))} |
190 | 190 | } |
191 | 191 | } |
192 | 192 | } |
|
0 commit comments