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