fix bugs in 'LineGap.subRight' (we were not passing nextIdx in recursion properly)

This commit is contained in:
2025-09-30 05:23:31 +01:00
parent 14bb447289
commit 265e6e1a90

View File

@@ -2263,41 +2263,31 @@ struct
end end
fun subRight (findIdx, curIdx, hd, tl) = fun subRight (findIdx, curIdx, hd, tl) =
if findIdx > curIdx + String.size hd - 1 then let
val nextIdx = curIdx + String.size hd
in
if findIdx > nextIdx - 1 then
case tl of case tl of
hd :: tl => hd :: tl => subRight (findIdx, nextIdx, hd, tl)
if findIdx > curIdx + String.size hd - 1 then
subRight (findIdx, curIdx + String.size hd, hd, tl)
else
let val strIdx = findIdx - curIdx
in String.sub (hd, strIdx)
end
| [] => raise Fail "not found" | [] => raise Fail "not found"
else else
let val strIdx = findIdx - curIdx let val strIdx = findIdx - curIdx
in String.sub (hd, strIdx) in String.sub (hd, strIdx)
end end
end
fun subLeft (findIdx, curIdx, hd, tl) = fun subLeft (findIdx, curIdx, hd, tl) =
if findIdx < curIdx - String.size hd then
case tl of
hd :: tl =>
if findIdx < curIdx - String.size hd then
subLeft (findIdx, curIdx - String.size hd, hd, tl)
else
let let
val prevIdx = curIdx - String.size hd val prevIdx = curIdx - String.size hd
val strIdx = findIdx - prevIdx
in in
String.sub (hd, strIdx) if findIdx < prevIdx then
end case tl of
hd :: tl => subLeft (findIdx, prevIdx, hd, tl)
| [] => raise Fail "not found" | [] => raise Fail "not found"
else else
let let val strIdx = findIdx - prevIdx
val prevIdx = curIdx - String.size hd in String.sub (hd, strIdx)
val strIdx = findIdx - prevIdx end
in
String.sub (hd, strIdx)
end end
fun sub (findIdx, buffer: t) = fun sub (findIdx, buffer: t) =