Skip to content
Snippets Groups Projects
Commit 61023686 authored by Marijn Haverbeke's avatar Marijn Haverbeke
Browse files

[searchcursor addon] Fix infinite loop when a match starts inside a composed char

Closes #4839
parent a7f209d0
No related branches found
No related tags found
No related merge requests found
...@@ -128,11 +128,13 @@ ...@@ -128,11 +128,13 @@
// (compensating for codepoints increasing in number during folding) // (compensating for codepoints increasing in number during folding)
function adjustPos(orig, folded, pos, foldFunc) { function adjustPos(orig, folded, pos, foldFunc) {
if (orig.length == folded.length) return pos if (orig.length == folded.length) return pos
for (var pos1 = Math.min(pos, orig.length);;) { for (var min = 0, max = pos + Math.max(0, orig.length - folded.length);;) {
var len1 = foldFunc(orig.slice(0, pos1)).length if (min == max) return min
if (len1 < pos) ++pos1 let mid = (min + max) >> 1
else if (len1 > pos) --pos1 var len = foldFunc(orig.slice(0, mid)).length
else return pos1 if (len == pos) return mid
else if (len > pos) max = mid - 1
else min = mid + 1
} }
} }
......
...@@ -74,4 +74,10 @@ ...@@ -74,4 +74,10 @@
run(doc, "</b>", true, 0, 8, 0, 12, 1, 8, 1, 12); run(doc, "</b>", true, 0, 8, 0, 12, 1, 8, 1, 12);
run(doc, "İİ", true, 0, 3, 0, 5, 0, 6, 0, 8); run(doc, "İİ", true, 0, 3, 0, 5, 0, 6, 0, 8);
}); });
test("normalize", function() {
var doc = new CodeMirror.Doc("yılbaşı\n수 있을까")
run(doc, "s", false, 0, 5, 0, 6)
run(doc, "", false, 1, 2, 1, 3)
})
})(); })();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment