From 14bb447289622fc3408d0c62e81c4ff80eb45462 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Mon, 29 Sep 2025 22:29:28 +0100 Subject: [PATCH] fix known errors in LineGap.sub function --- src/line_gap.sml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/line_gap.sml b/src/line_gap.sml index d64b7bf..bd7dc6e 100644 --- a/src/line_gap.sml +++ b/src/line_gap.sml @@ -2263,10 +2263,10 @@ struct end fun subRight (findIdx, curIdx, hd, tl) = - if findIdx > curIdx + String.size hd then + if findIdx > curIdx + String.size hd - 1 then case tl of hd :: tl => - if findIdx > curIdx + String.size hd then + if findIdx > curIdx + String.size hd - 1 then subRight (findIdx, curIdx + String.size hd, hd, tl) else let val strIdx = findIdx - curIdx @@ -2301,14 +2301,14 @@ struct end fun sub (findIdx, buffer: t) = - if findIdx < #idx buffer then - case #leftStrings buffer of - hd :: tl => subLeft (findIdx, #idx buffer, hd, tl) - | [] => raise Fail "not found" - else + if findIdx >= #idx buffer then case #rightStrings buffer of hd :: tl => subRight (findIdx, #idx buffer, hd, tl) | [] => raise Fail "not found" + else + case #leftStrings buffer of + hd :: tl => subLeft (findIdx, #idx buffer, hd, tl) + | [] => raise Fail "not found" local fun consIfNotEmpty (s, acc) =