From d71fd803985395484dd789857797d5213a9e6b86 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sat, 20 Jul 2024 00:14:21 +0100 Subject: [PATCH] amend few bugs - now there is another error with buffer having wrong index --- src/line_gap.sml | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/line_gap.sml b/src/line_gap.sml index aa970b4..bffd78b 100644 --- a/src/line_gap.sml +++ b/src/line_gap.sml @@ -1509,15 +1509,21 @@ struct let val length = start - prevIdx val newStr = String.substring (leftStringsHd, 0, length) - val midpoint = binSearch (String.size newStr - 1, leftLinesHd) val newLines = - let - val _ = println "1461" - val slice = VectorSlice.slice - (leftLinesHd, 0, SOME (midpoint + 1)) - in - VectorSlice.vector slice - end + if Vector.length leftLinesHd > 0 then + let + val midpoint = binSearch + (String.size newStr - 1, leftLinesHd) + val _ = println "1461" + val _ = println + ("vlen = " ^ (Int.toString (Vector.length leftLinesHd))) + val slice = VectorSlice.slice + (leftLinesHd, 0, SOME (midpoint + 1)) + in + VectorSlice.vector slice + end + else + Vector.fromList [] val _ = println "1433" in { idx = prevIdx + String.size newStr @@ -1906,17 +1912,20 @@ struct ) end | (_, _) => - (* Left strings and lines are empty, so just return. *) + (* Right strings and lines are empty, so can't join. *) let val _ = println "1814" in - { idx = 0 - , line = 0 - , leftStrings = [] - , leftLines = [] - , rightStrings = rightStrings - , rightLines = rightLines - } + deleteLeftFromHere + ( start + , prevIdx + , curLine - Vector.length leftLinesHd + , leftStringsTl + , leftLinesTl + , [leftStringsHd] + , [leftLinesHd] + ) + end) end | (_, _) =>