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