Skip to content

Commit f1319c8

Browse files
committed
[searchcursor addon] Make adjustPos use the right folding function
Issue #4824
1 parent b2b1737 commit f1319c8

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

addon/search/searchcursor.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@
126126

127127
// Maps a position in a case-folded line back to a position in the original line
128128
// (compensating for codepoints increasing in number during folding)
129-
function adjustPos(orig, folded, pos) {
129+
function adjustPos(orig, folded, pos, foldFunc) {
130130
if (orig.length == folded.length) return pos
131131
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
133133
if (len1 < pos) ++pos1
134134
else if (len1 > pos) --pos1
135135
else return pos1
@@ -148,18 +148,18 @@
148148
if (lines.length == 1) {
149149
var found = string.indexOf(lines[0])
150150
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)}
154154
} else {
155155
var cutFrom = string.length - lines[0].length
156156
if (string.slice(cutFrom) != lines[0]) continue search
157157
for (var i = 1; i < lines.length - 1; i++)
158158
if (fold(doc.getLine(line + i)) != lines[i]) continue search
159159
var end = doc.getLine(line + lines.length - 1), endString = fold(end), lastLine = lines[lines.length - 1]
160160
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))}
163163
}
164164
}
165165
}
@@ -176,17 +176,17 @@
176176
if (lines.length == 1) {
177177
var found = string.lastIndexOf(lines[0])
178178
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))}
181181
} else {
182182
var lastLine = lines[lines.length - 1]
183183
if (string.slice(0, lastLine.length) != lastLine) continue search
184184
for (var i = 1, start = line - lines.length + 1; i < lines.length - 1; i++)
185185
if (fold(doc.getLine(start + i)) != lines[i]) continue search
186186
var top = doc.getLine(line + 1 - lines.length), topString = fold(top)
187187
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))}
190190
}
191191
}
192192
}

0 commit comments

Comments
 (0)