fix bug in index metadata in line_gap.sml (make sure we add and subtract by size of string by calling String.size)
This commit is contained in:
159
src/line_gap.sml
159
src/line_gap.sml
@@ -1347,8 +1347,8 @@ struct
|
||||
* while origIdx considers index to return
|
||||
* once buffer is done deleting. *)
|
||||
deleteRightFromHere
|
||||
( curIdx + String.size newString
|
||||
, curLine + Vector.length newLines
|
||||
( curIdx + String.size newLeftStringsHd
|
||||
, curLine + Vector.length newLeftLinesHd
|
||||
, nextIdx
|
||||
, finish
|
||||
, newLeftStringsHd :: leftStringsTl
|
||||
@@ -1372,7 +1372,7 @@ struct
|
||||
)
|
||||
| (_, _) =>
|
||||
deleteRightFromHere
|
||||
( nextIdx
|
||||
( curIdx + String.size newString
|
||||
, curLine + Vector.length newLines
|
||||
, nextIdx
|
||||
, finish
|
||||
@@ -1418,7 +1418,7 @@ struct
|
||||
else
|
||||
Vector.fromList []
|
||||
in
|
||||
{ idx = curIdx + sub1Length
|
||||
{ idx = curIdx + String.size sub1
|
||||
, line = curLine + Vector.length sub1Lines
|
||||
, leftStrings = sub1 :: leftStrings
|
||||
, leftLines = sub1Lines :: leftLines
|
||||
@@ -1444,7 +1444,7 @@ struct
|
||||
VectorSlice.vector slice
|
||||
end
|
||||
in
|
||||
{ idx = curIdx + strLength
|
||||
{ idx = curIdx + String.size str
|
||||
, line = curLine + Vector.length newLeftLines
|
||||
, leftStrings = str :: leftStrings
|
||||
, leftLines = newLeftLines :: leftLines
|
||||
@@ -1460,7 +1460,7 @@ struct
|
||||
* So pass the rightStringsTl and rightLinesTl to a function that
|
||||
* will delete rightwards if it needs to, or else terminates. *)
|
||||
deleteRightFromHere
|
||||
( nextIdx
|
||||
( curIdx + String.size rightStringsHd
|
||||
, curLine + Vector.length rightLinesHd
|
||||
, nextIdx
|
||||
, finish
|
||||
@@ -1759,7 +1759,7 @@ struct
|
||||
Vector.fromList []
|
||||
end
|
||||
in
|
||||
{ idx = prevIdx + sub1Length
|
||||
{ idx = prevIdx + String.size sub1
|
||||
, line =
|
||||
(curLine - Vector.length leftLinesHd)
|
||||
+ Vector.length sub1Lines
|
||||
@@ -1954,10 +1954,7 @@ struct
|
||||
|
||||
local
|
||||
fun consIfNotEmpty (s, acc) =
|
||||
if String.size s > 0 then
|
||||
s :: acc
|
||||
else
|
||||
acc
|
||||
if String.size s > 0 then s :: acc else acc
|
||||
|
||||
(* We build up the string list and, at the end,
|
||||
* we always make sure to reverse the list too
|
||||
@@ -1988,12 +1985,7 @@ struct
|
||||
List.rev acc
|
||||
end
|
||||
end
|
||||
| [] =>
|
||||
let
|
||||
val acc = consIfNotEmpty (endWith, acc)
|
||||
in
|
||||
List.rev acc
|
||||
end
|
||||
| [] => let val acc = consIfNotEmpty (endWith, acc) in List.rev acc end
|
||||
|
||||
fun moveRightAndSub (start, finish, curIdx, right, endWith) =
|
||||
case right of
|
||||
@@ -2024,9 +2016,7 @@ struct
|
||||
val length = subfinish - substart
|
||||
val str = String.substring (hd, substart, length)
|
||||
in
|
||||
if String.size endWith > 0
|
||||
then str ^ endWith
|
||||
else str
|
||||
if String.size endWith > 0 then str ^ endWith else str
|
||||
end
|
||||
else
|
||||
(* have to get substring from middle to end *)
|
||||
@@ -2035,18 +2025,14 @@ struct
|
||||
val length = String.size hd - substart
|
||||
val str = String.substring (hd, substart, length)
|
||||
in
|
||||
if String.size endWith > 0
|
||||
then str ^ endWith
|
||||
else str
|
||||
if String.size endWith > 0 then str ^ endWith else str
|
||||
end
|
||||
else
|
||||
(* nextIdx = start
|
||||
* so we have to ignore this string
|
||||
* and start building acc from tl *)
|
||||
let
|
||||
val acc = subRightFromHere (nextIdx, finish, tl, [], endWith)
|
||||
in
|
||||
String.concat acc
|
||||
let val acc = subRightFromHere (nextIdx, finish, tl, [], endWith)
|
||||
in String.concat acc
|
||||
end
|
||||
end
|
||||
| [] =>
|
||||
@@ -2078,19 +2064,15 @@ struct
|
||||
else
|
||||
(* start = prevIdx
|
||||
* add hd to acc and return *)
|
||||
let
|
||||
val acc = hd :: acc
|
||||
in
|
||||
String.concat acc
|
||||
let val acc = hd :: acc
|
||||
in String.concat acc
|
||||
end
|
||||
end
|
||||
| [] => String.concat acc
|
||||
|
||||
fun subFromLeftAndRight (start, finish, curIdx, left, right, endWith) =
|
||||
let
|
||||
val acc = subRightFromHere (curIdx, finish, right, [], endWith)
|
||||
in
|
||||
subLeftFromHere (start, curIdx, left, acc)
|
||||
let val acc = subRightFromHere (curIdx, finish, right, [], endWith)
|
||||
in subLeftFromHere (start, curIdx, left, acc)
|
||||
end
|
||||
|
||||
fun moveLeftAndSub (start, finish, curIdx, left, endWith) =
|
||||
@@ -2108,7 +2090,8 @@ struct
|
||||
* and continue substring leftwards *)
|
||||
let
|
||||
val length = finish - prevIdx
|
||||
val str = String.substring (hd, 0, length) val acc = [str, endWith]
|
||||
val str = String.substring (hd, 0, length)
|
||||
val acc = [str, endWith]
|
||||
in
|
||||
subLeftFromHere (start, prevIdx, tl, acc)
|
||||
end
|
||||
@@ -2121,9 +2104,7 @@ struct
|
||||
val length = subfinish - substart
|
||||
val str = String.substring (hd, substart, length)
|
||||
in
|
||||
if String.size endWith > 0
|
||||
then str ^ endWith
|
||||
else str
|
||||
if String.size endWith > 0 then str ^ endWith else str
|
||||
end
|
||||
else
|
||||
(* prevIdx = start
|
||||
@@ -2133,9 +2114,7 @@ struct
|
||||
val length = String.size hd - subfinish
|
||||
val str = String.substring (hd, 0, length)
|
||||
in
|
||||
if String.size endWith > 0
|
||||
then str ^ endWith
|
||||
else str
|
||||
if String.size endWith > 0 then str ^ endWith else str
|
||||
end
|
||||
else
|
||||
(* prevIdx = finish
|
||||
@@ -2163,7 +2142,7 @@ struct
|
||||
String.concat acc
|
||||
end
|
||||
in
|
||||
fun substringWithEnd (start, length, buffer : t, endWith) =
|
||||
fun substringWithEnd (start, length, buffer: t, endWith) =
|
||||
let
|
||||
val finish = start + length
|
||||
val {idx, leftStrings, rightStrings, ...} = buffer
|
||||
@@ -2171,7 +2150,7 @@ struct
|
||||
sub (start, finish, idx, leftStrings, rightStrings, endWith)
|
||||
end
|
||||
|
||||
fun nullSubstring (start, length, buffer : t) =
|
||||
fun nullSubstring (start, length, buffer: t) =
|
||||
let
|
||||
val finish = start + length
|
||||
val {idx, leftStrings, rightStrings, ...} = buffer
|
||||
@@ -2179,7 +2158,7 @@ struct
|
||||
sub (start, finish, idx, leftStrings, rightStrings, "\u0000")
|
||||
end
|
||||
|
||||
fun substring (start, length, buffer : t) =
|
||||
fun substring (start, length, buffer: t) =
|
||||
let
|
||||
val finish = start + length
|
||||
val {idx, leftStrings, rightStrings, ...} = buffer
|
||||
@@ -2251,8 +2230,7 @@ struct
|
||||
({idx, line, leftStrings, leftLines, rightStrings, rightLines}: t) =
|
||||
helpGoToStart (idx, line, leftStrings, leftLines, rightStrings, rightLines)
|
||||
|
||||
fun helpGoToEnd
|
||||
(idx, line, leftStrings, leftLines, rightStrings, rightLines) =
|
||||
fun helpGoToEnd (idx, line, leftStrings, leftLines, rightStrings, rightLines) =
|
||||
case (rightStrings, rightLines) of
|
||||
(rStrHd :: rStrTl, rLnHd :: rLnTl) =>
|
||||
(case (leftStrings, leftLines) of
|
||||
@@ -2310,8 +2288,7 @@ struct
|
||||
, rightLines = []
|
||||
}
|
||||
|
||||
fun goToEnd
|
||||
({idx, line, leftStrings, leftLines, rightStrings, rightLines}: t) =
|
||||
fun goToEnd ({idx, line, leftStrings, leftLines, rightStrings, rightLines}: t) =
|
||||
helpGoToEnd (idx, line, leftStrings, leftLines, rightStrings, rightLines)
|
||||
|
||||
(* function to abstract leftwards movement.
|
||||
@@ -2329,9 +2306,17 @@ struct
|
||||
* the search number, this parameter is just passed to fGoLeft.
|
||||
* *)
|
||||
fun moveLeft
|
||||
( idx, line, searchTo
|
||||
, leftStrings, leftLines, rightStrings, rightLines
|
||||
, lStrHd, lStrTl, lLnHd, lLnTl
|
||||
( idx
|
||||
, line
|
||||
, searchTo
|
||||
, leftStrings
|
||||
, leftLines
|
||||
, rightStrings
|
||||
, rightLines
|
||||
, lStrHd
|
||||
, lStrTl
|
||||
, lLnHd
|
||||
, lLnTl
|
||||
, fGoLeft
|
||||
) =
|
||||
case (rightStrings, rightLines) of
|
||||
@@ -2386,9 +2371,17 @@ struct
|
||||
|
||||
(* same as moveLeft function, except it move rightwards instead *)
|
||||
fun moveRight
|
||||
( idx, line, searchTo
|
||||
, leftStrings, leftLines, rightStrings, rightLines
|
||||
, rStrHd, rStrTl, rLnHd, rLnTl
|
||||
( idx
|
||||
, line
|
||||
, searchTo
|
||||
, leftStrings
|
||||
, leftLines
|
||||
, rightStrings
|
||||
, rightLines
|
||||
, rStrHd
|
||||
, rStrTl
|
||||
, rLnHd
|
||||
, rLnTl
|
||||
, fGoRight
|
||||
) =
|
||||
case (leftStrings, leftLines) of
|
||||
@@ -2448,9 +2441,17 @@ struct
|
||||
if searchLine < line - Vector.length lLnHd then
|
||||
(* move leftwards, joining if possible *)
|
||||
moveLeft
|
||||
( idx, line, searchLine
|
||||
, leftStrings, leftLines, rightStrings, rightLines
|
||||
, lStrHd, lStrTl, lLnHd, lLnTl
|
||||
( idx
|
||||
, line
|
||||
, searchLine
|
||||
, leftStrings
|
||||
, leftLines
|
||||
, rightStrings
|
||||
, rightLines
|
||||
, lStrHd
|
||||
, lStrTl
|
||||
, lLnHd
|
||||
, lLnTl
|
||||
, helpGoToLineLeft
|
||||
)
|
||||
else
|
||||
@@ -2479,9 +2480,17 @@ struct
|
||||
if searchLine > line + Vector.length rLnHd then
|
||||
(* have to move rightwards *)
|
||||
moveRight
|
||||
( idx, line, searchLine
|
||||
, leftStrings, leftLines, rightStrings, rightLines
|
||||
, rStrHd, rStrTl, rLnHd, rLnTl
|
||||
( idx
|
||||
, line
|
||||
, searchLine
|
||||
, leftStrings
|
||||
, leftLines
|
||||
, rightStrings
|
||||
, rightLines
|
||||
, rStrHd
|
||||
, rStrTl
|
||||
, rLnHd
|
||||
, rLnTl
|
||||
, helpGoToLineRight
|
||||
)
|
||||
else
|
||||
@@ -2538,9 +2547,17 @@ struct
|
||||
if searchIdx < idx - String.size lStrHd then
|
||||
(* move leftwards, joining if possible *)
|
||||
moveLeft
|
||||
( idx, line, searchIdx
|
||||
, leftStrings, leftLines, rightStrings, rightLines
|
||||
, lStrHd, lStrTl, lLnHd, lLnTl
|
||||
( idx
|
||||
, line
|
||||
, searchIdx
|
||||
, leftStrings
|
||||
, leftLines
|
||||
, rightStrings
|
||||
, rightLines
|
||||
, lStrHd
|
||||
, lStrTl
|
||||
, lLnHd
|
||||
, lLnTl
|
||||
, helpGoToIdxLeft
|
||||
)
|
||||
else
|
||||
@@ -2569,9 +2586,17 @@ struct
|
||||
if searchIdx > idx + String.size rStrHd then
|
||||
(* have to move rightwards *)
|
||||
moveRight
|
||||
( idx, line, searchIdx
|
||||
, leftStrings, leftLines, rightStrings, rightLines
|
||||
, rStrHd, rStrTl, rLnHd, rLnTl
|
||||
( idx
|
||||
, line
|
||||
, searchIdx
|
||||
, leftStrings
|
||||
, leftLines
|
||||
, rightStrings
|
||||
, rightLines
|
||||
, rStrHd
|
||||
, rStrTl
|
||||
, rLnHd
|
||||
, rLnTl
|
||||
, helpGoToIdxRight
|
||||
)
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user