begin adding textLength and lineLength values in line_gap.sml (they are currently kept up to date only in the insert functions)
This commit is contained in:
102
src/line_gap.sml
102
src/line_gap.sml
@@ -2,10 +2,12 @@ signature LINE_GAP =
|
|||||||
sig
|
sig
|
||||||
type t =
|
type t =
|
||||||
{ idx: int
|
{ idx: int
|
||||||
|
, textLength: int
|
||||||
, leftStrings: string list
|
, leftStrings: string list
|
||||||
, rightStrings: string list
|
, rightStrings: string list
|
||||||
|
|
||||||
, line: int
|
, line: int
|
||||||
|
, lineLength: int
|
||||||
, leftLines: int vector list
|
, leftLines: int vector list
|
||||||
, rightLines: int vector list
|
, rightLines: int vector list
|
||||||
}
|
}
|
||||||
@@ -70,10 +72,12 @@ struct
|
|||||||
|
|
||||||
type t =
|
type t =
|
||||||
{ idx: int
|
{ idx: int
|
||||||
|
, textLength: int
|
||||||
, leftStrings: string list
|
, leftStrings: string list
|
||||||
, rightStrings: string list
|
, rightStrings: string list
|
||||||
|
|
||||||
, line: int
|
, line: int
|
||||||
|
, lineLength: int
|
||||||
, leftLines: int vector list
|
, leftLines: int vector list
|
||||||
, rightLines: int vector list
|
, rightLines: int vector list
|
||||||
}
|
}
|
||||||
@@ -83,21 +87,29 @@ struct
|
|||||||
|
|
||||||
val empty =
|
val empty =
|
||||||
{ idx = 0
|
{ idx = 0
|
||||||
|
, textLength = 0
|
||||||
, leftStrings = []
|
, leftStrings = []
|
||||||
, rightStrings = []
|
, rightStrings = []
|
||||||
, line = 0
|
, line = 0
|
||||||
|
, lineLength = 0
|
||||||
, leftLines = []
|
, leftLines = []
|
||||||
, rightLines = []
|
, rightLines = []
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fromString str =
|
fun fromString str =
|
||||||
{ idx = 0
|
let
|
||||||
, leftStrings = []
|
val linebreaks = countLineBreaks str
|
||||||
, rightStrings = [str]
|
in
|
||||||
, line = 0
|
{ idx = 0
|
||||||
, leftLines = []
|
, textLength = String.size str
|
||||||
, rightLines = [countLineBreaks str]
|
, leftStrings = []
|
||||||
}
|
, rightStrings = [str]
|
||||||
|
, line = 0
|
||||||
|
, lineLength = Vector.length linebreaks
|
||||||
|
, leftLines = []
|
||||||
|
, rightLines = [linebreaks]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
local
|
local
|
||||||
fun helpToString (acc, input) =
|
fun helpToString (acc, input) =
|
||||||
@@ -204,6 +216,8 @@ struct
|
|||||||
, leftLines
|
, leftLines
|
||||||
, rightStrings
|
, rightStrings
|
||||||
, rightLines
|
, rightLines
|
||||||
|
, textLength
|
||||||
|
, lineLength
|
||||||
) : t =
|
) : t =
|
||||||
case (leftStrings, leftLines) of
|
case (leftStrings, leftLines) of
|
||||||
(strHd :: strTl, lineHd :: lineTl) =>
|
(strHd :: strTl, lineHd :: lineTl) =>
|
||||||
@@ -228,7 +242,9 @@ struct
|
|||||||
val newLeftLines = newLinesHd :: lineTl
|
val newLeftLines = newLinesHd :: lineTl
|
||||||
in
|
in
|
||||||
{ idx = newIdx
|
{ idx = newIdx
|
||||||
|
, textLength = textLength
|
||||||
, line = newLine
|
, line = newLine
|
||||||
|
, lineLength = lineLength
|
||||||
, leftStrings = newLeftString
|
, leftStrings = newLeftString
|
||||||
, leftLines = newLeftLines
|
, leftLines = newLeftLines
|
||||||
, rightStrings = rightStrings
|
, rightStrings = rightStrings
|
||||||
@@ -238,7 +254,9 @@ struct
|
|||||||
else
|
else
|
||||||
(* Does not fit in limit, so cons instead.*)
|
(* Does not fit in limit, so cons instead.*)
|
||||||
{ idx = curIdx + String.size newString
|
{ idx = curIdx + String.size newString
|
||||||
|
, textLength = textLength
|
||||||
, line = curLine + Vector.length newLines
|
, line = curLine + Vector.length newLines
|
||||||
|
, lineLength = lineLength
|
||||||
, leftStrings = newString :: leftStrings
|
, leftStrings = newString :: leftStrings
|
||||||
, leftLines = newLines :: leftLines
|
, leftLines = newLines :: leftLines
|
||||||
, rightStrings = rightStrings
|
, rightStrings = rightStrings
|
||||||
@@ -252,7 +270,9 @@ struct
|
|||||||
* So we don't need to perform addition or consing.
|
* So we don't need to perform addition or consing.
|
||||||
*)
|
*)
|
||||||
{ idx = String.size newString
|
{ idx = String.size newString
|
||||||
|
, textLength = textLength
|
||||||
, line = Vector.length newLines
|
, line = Vector.length newLines
|
||||||
|
, lineLength = lineLength
|
||||||
, leftStrings = [newString]
|
, leftStrings = [newString]
|
||||||
, leftLines = [newLines]
|
, leftLines = [newLines]
|
||||||
, rightStrings = rightStrings
|
, rightStrings = rightStrings
|
||||||
@@ -274,6 +294,8 @@ struct
|
|||||||
, leftStringsTl
|
, leftStringsTl
|
||||||
, leftLinesHd
|
, leftLinesHd
|
||||||
, leftLinesTl
|
, leftLinesTl
|
||||||
|
, textLength
|
||||||
|
, lineLength
|
||||||
) : t =
|
) : t =
|
||||||
if idx = prevIdx then
|
if idx = prevIdx then
|
||||||
(* Need to insert at the start of the left list. *)
|
(* Need to insert at the start of the left list. *)
|
||||||
@@ -292,7 +314,9 @@ struct
|
|||||||
)
|
)
|
||||||
in
|
in
|
||||||
{ idx = curIdx + String.size newString
|
{ idx = curIdx + String.size newString
|
||||||
|
, textLength = textLength
|
||||||
, line = curLine + Vector.length newLines
|
, line = curLine + Vector.length newLines
|
||||||
|
, lineLength = lineLength
|
||||||
, leftStrings = (newString ^ leftStringsHd) :: leftStringsTl
|
, leftStrings = (newString ^ leftStringsHd) :: leftStringsTl
|
||||||
, leftLines = joinedLines :: leftLinesTl
|
, leftLines = joinedLines :: leftLinesTl
|
||||||
, rightStrings = rightStrings
|
, rightStrings = rightStrings
|
||||||
@@ -302,7 +326,9 @@ struct
|
|||||||
else
|
else
|
||||||
(* Just cons everything; no way we can join while staying in limit. *)
|
(* Just cons everything; no way we can join while staying in limit. *)
|
||||||
{ idx = curIdx + String.size newString
|
{ idx = curIdx + String.size newString
|
||||||
|
, textLength = textLength
|
||||||
, line = curLine + Vector.length newLines
|
, line = curLine + Vector.length newLines
|
||||||
|
, lineLength = lineLength
|
||||||
, leftStrings = leftStringsHd :: newString :: leftStringsTl
|
, leftStrings = leftStringsHd :: newString :: leftStringsTl
|
||||||
, leftLines = leftLinesHd :: newLines :: leftLinesTl
|
, leftLines = leftLinesHd :: newLines :: leftLinesTl
|
||||||
, rightStrings = rightStrings
|
, rightStrings = rightStrings
|
||||||
@@ -343,7 +369,9 @@ struct
|
|||||||
Vector.map (fn el => el + String.size strSub1) newLines
|
Vector.map (fn el => el + String.size strSub1) newLines
|
||||||
in
|
in
|
||||||
{ idx = curIdx + String.size newString
|
{ idx = curIdx + String.size newString
|
||||||
|
, textLength = textLength
|
||||||
, line = curLine + Vector.length newLines
|
, line = curLine + Vector.length newLines
|
||||||
|
, lineLength = lineLength
|
||||||
, leftStrings = joinedString :: leftStringsTl
|
, leftStrings = joinedString :: leftStringsTl
|
||||||
, leftLines = joinedLines :: leftLinesTl
|
, leftLines = joinedLines :: leftLinesTl
|
||||||
, rightStrings = rightStrings
|
, rightStrings = rightStrings
|
||||||
@@ -377,9 +405,11 @@ struct
|
|||||||
)
|
)
|
||||||
in
|
in
|
||||||
{ idx = prevIdx + String.size strSub1 + String.size newString
|
{ idx = prevIdx + String.size strSub1 + String.size newString
|
||||||
|
, textLength = textLength
|
||||||
, line =
|
, line =
|
||||||
(curLine - Vector.length leftLinesHd)
|
(curLine - Vector.length leftLinesHd)
|
||||||
+ Vector.length newLeftLines
|
+ Vector.length newLeftLines
|
||||||
|
, lineLength = lineLength
|
||||||
, leftStrings = (strSub1 ^ newString) :: leftStringsTl
|
, leftStrings = (strSub1 ^ newString) :: leftStringsTl
|
||||||
, leftLines = newLeftLines :: leftLinesTl
|
, leftLines = newLeftLines :: leftLinesTl
|
||||||
, rightStrings = strSub2 :: rightStrings
|
, rightStrings = strSub2 :: rightStrings
|
||||||
@@ -395,9 +425,11 @@ struct
|
|||||||
Vector.map (fn idx => idx - String.size strSub1) leftLinesHd
|
Vector.map (fn idx => idx - String.size strSub1) leftLinesHd
|
||||||
in
|
in
|
||||||
{ idx = prevIdx + String.size strSub1 + String.size newString
|
{ idx = prevIdx + String.size strSub1 + String.size newString
|
||||||
|
, textLength = textLength
|
||||||
, line =
|
, line =
|
||||||
(curLine - Vector.length leftLinesHd)
|
(curLine - Vector.length leftLinesHd)
|
||||||
+ Vector.length newLeftLines
|
+ Vector.length newLeftLines
|
||||||
|
, lineLength = lineLength
|
||||||
, leftStrings = (strSub1 ^ newString) :: leftStringsTl
|
, leftStrings = (strSub1 ^ newString) :: leftStringsTl
|
||||||
, leftLines = newLeftLines :: leftLinesTl
|
, leftLines = newLeftLines :: leftLinesTl
|
||||||
, rightStrings = strSub2 :: rightStrings
|
, rightStrings = strSub2 :: rightStrings
|
||||||
@@ -440,7 +472,9 @@ struct
|
|||||||
)
|
)
|
||||||
in
|
in
|
||||||
{ idx = prevIdx + String.size strSub1
|
{ idx = prevIdx + String.size strSub1
|
||||||
|
, textLength = textLength
|
||||||
, line = (curLine - Vector.length leftLinesHd) + midpoint
|
, line = (curLine - Vector.length leftLinesHd) + midpoint
|
||||||
|
, lineLength = lineLength
|
||||||
, leftStrings = strSub1 :: leftStringsTl
|
, leftStrings = strSub1 :: leftStringsTl
|
||||||
, leftLines = newLeftLines :: leftLinesTl
|
, leftLines = newLeftLines :: leftLinesTl
|
||||||
, rightStrings = (newString ^ strSub2) :: rightStrings
|
, rightStrings = (newString ^ strSub2) :: rightStrings
|
||||||
@@ -468,9 +502,11 @@ struct
|
|||||||
- String.size strSub1)
|
- String.size strSub1)
|
||||||
in
|
in
|
||||||
{ idx = prevIdx + String.size strSub1 + String.size newString
|
{ idx = prevIdx + String.size strSub1 + String.size newString
|
||||||
|
, textLength = textLength
|
||||||
, line =
|
, line =
|
||||||
(curLine - String.size leftStringsHd) + midpoint
|
(curLine - String.size leftStringsHd) + midpoint
|
||||||
+ Vector.length newLines
|
+ Vector.length newLines
|
||||||
|
, lineLength = lineLength
|
||||||
, leftStrings = newString :: strSub1 :: leftStringsTl
|
, leftStrings = newString :: strSub1 :: leftStringsTl
|
||||||
, leftLines = newLines :: lineSub1 :: leftLinesTl
|
, leftLines = newLines :: lineSub1 :: leftLinesTl
|
||||||
, rightStrings = strSub2 :: rightStrings
|
, rightStrings = strSub2 :: rightStrings
|
||||||
@@ -489,6 +525,8 @@ struct
|
|||||||
, leftLines
|
, leftLines
|
||||||
, rightStrings
|
, rightStrings
|
||||||
, rightLines
|
, rightLines
|
||||||
|
, textLength
|
||||||
|
, lineLength
|
||||||
) =
|
) =
|
||||||
case (leftStrings, leftLines) of
|
case (leftStrings, leftLines) of
|
||||||
(leftStringsHd :: leftStringsTl, leftLinesHd :: leftLinesTl) =>
|
(leftStringsHd :: leftStringsTl, leftLinesHd :: leftLinesTl) =>
|
||||||
@@ -543,6 +581,8 @@ struct
|
|||||||
, leftLinesTl
|
, leftLinesTl
|
||||||
, newRightStringsHd :: rightStringsTl
|
, newRightStringsHd :: rightStringsTl
|
||||||
, newRightLinesHd :: rightLinesTl
|
, newRightLinesHd :: rightLinesTl
|
||||||
|
, textLength
|
||||||
|
, lineLength
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -556,6 +596,8 @@ struct
|
|||||||
, leftLinesTl
|
, leftLinesTl
|
||||||
, leftStringsHd :: rightStrings
|
, leftStringsHd :: rightStrings
|
||||||
, leftLinesHd :: rightLines
|
, leftLinesHd :: rightLines
|
||||||
|
, textLength
|
||||||
|
, lineLength
|
||||||
)
|
)
|
||||||
| (_, _) =>
|
| (_, _) =>
|
||||||
moveLeftAndIns
|
moveLeftAndIns
|
||||||
@@ -568,6 +610,8 @@ struct
|
|||||||
, leftLinesTl
|
, leftLinesTl
|
||||||
, leftStringsHd :: rightStrings
|
, leftStringsHd :: rightStrings
|
||||||
, leftLinesHd :: rightLines
|
, leftLinesHd :: rightLines
|
||||||
|
, textLength
|
||||||
|
, lineLength
|
||||||
))
|
))
|
||||||
else
|
else
|
||||||
(* Insertion is somewhere between the head of the left list,
|
(* Insertion is somewhere between the head of the left list,
|
||||||
@@ -587,13 +631,17 @@ struct
|
|||||||
, leftStringsTl
|
, leftStringsTl
|
||||||
, leftLinesHd
|
, leftLinesHd
|
||||||
, leftLinesTl
|
, leftLinesTl
|
||||||
|
, textLength
|
||||||
|
, lineLength
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
| (_, _) =>
|
| (_, _) =>
|
||||||
(* Left list is empty, so need to cons or join.
|
(* Left list is empty, so need to cons or join.
|
||||||
* Just set left string/list as newString/newLines. *)
|
* Just set left string/list as newString/newLines. *)
|
||||||
{ idx = String.size newString
|
{ idx = String.size newString
|
||||||
|
, textLength = textLength
|
||||||
, line = Vector.length newLines
|
, line = Vector.length newLines
|
||||||
|
, lineLength = lineLength
|
||||||
, leftStrings = [newString]
|
, leftStrings = [newString]
|
||||||
, leftLines = [newLines]
|
, leftLines = [newLines]
|
||||||
, rightStrings = rightStrings
|
, rightStrings = rightStrings
|
||||||
@@ -615,6 +663,8 @@ struct
|
|||||||
, rightStringsTl
|
, rightStringsTl
|
||||||
, rightLinesHd: int vector
|
, rightLinesHd: int vector
|
||||||
, rightLinesTl
|
, rightLinesTl
|
||||||
|
, textLength
|
||||||
|
, lineLength
|
||||||
) : t =
|
) : t =
|
||||||
if idx = nextIdx then
|
if idx = nextIdx then
|
||||||
(* Need to put newString/newLines at the end of the right list's hd. *)
|
(* Need to put newString/newLines at the end of the right list's hd. *)
|
||||||
@@ -634,7 +684,9 @@ struct
|
|||||||
)
|
)
|
||||||
in
|
in
|
||||||
{ idx = curIdx
|
{ idx = curIdx
|
||||||
|
, textLength = textLength
|
||||||
, line = curLine
|
, line = curLine
|
||||||
|
, lineLength = lineLength
|
||||||
, leftStrings = leftStrings
|
, leftStrings = leftStrings
|
||||||
, leftLines = leftLines
|
, leftLines = leftLines
|
||||||
, rightStrings = newRightStringsHd :: rightStringsTl
|
, rightStrings = newRightStringsHd :: rightStringsTl
|
||||||
@@ -645,7 +697,9 @@ struct
|
|||||||
(* Cons newString and newLines to after-the-head,
|
(* Cons newString and newLines to after-the-head,
|
||||||
* because we can't join while staying in the limit.*)
|
* because we can't join while staying in the limit.*)
|
||||||
{ idx = curIdx
|
{ idx = curIdx
|
||||||
|
, textLength = textLength
|
||||||
, line = curLine
|
, line = curLine
|
||||||
|
, lineLength = lineLength
|
||||||
, leftStrings = leftStrings
|
, leftStrings = leftStrings
|
||||||
, leftLines = leftLines
|
, leftLines = leftLines
|
||||||
, rightStrings = rightStringsHd :: newString :: rightStringsTl
|
, rightStrings = rightStringsHd :: newString :: rightStringsTl
|
||||||
@@ -686,7 +740,9 @@ struct
|
|||||||
Vector.map (fn el => el + String.size strSub1) newLines
|
Vector.map (fn el => el + String.size strSub1) newLines
|
||||||
in
|
in
|
||||||
{ idx = curIdx
|
{ idx = curIdx
|
||||||
|
, textLength = textLength
|
||||||
, line = curLine
|
, line = curLine
|
||||||
|
, lineLength = lineLength
|
||||||
, leftStrings = leftStrings
|
, leftStrings = leftStrings
|
||||||
, leftLines = leftLines
|
, leftLines = leftLines
|
||||||
, rightStrings = newRightStringsHd :: rightStringsTl
|
, rightStrings = newRightStringsHd :: rightStringsTl
|
||||||
@@ -721,7 +777,9 @@ struct
|
|||||||
)
|
)
|
||||||
in
|
in
|
||||||
{ idx = curIdx + String.size newLeftStringsHd
|
{ idx = curIdx + String.size newLeftStringsHd
|
||||||
|
, textLength = textLength
|
||||||
, line = curLine + Vector.length newLeftLinesHd
|
, line = curLine + Vector.length newLeftLinesHd
|
||||||
|
, lineLength = lineLength
|
||||||
, leftStrings = newLeftStringsHd :: leftStrings
|
, leftStrings = newLeftStringsHd :: leftStrings
|
||||||
, leftLines = newLeftLinesHd :: leftLines
|
, leftLines = newLeftLinesHd :: leftLines
|
||||||
, rightStrings = strSub2 :: rightStringsTl
|
, rightStrings = strSub2 :: rightStringsTl
|
||||||
@@ -738,7 +796,9 @@ struct
|
|||||||
Vector.map (fn idx => idx - String.size strSub1) rightLinesHd
|
Vector.map (fn idx => idx - String.size strSub1) rightLinesHd
|
||||||
in
|
in
|
||||||
{ idx = curIdx + String.size newLeftStringsHd
|
{ idx = curIdx + String.size newLeftStringsHd
|
||||||
|
, textLength = textLength
|
||||||
, line = curLine + Vector.length newLeftLinesHd
|
, line = curLine + Vector.length newLeftLinesHd
|
||||||
|
, lineLength = lineLength
|
||||||
, leftStrings = newLeftStringsHd :: leftStrings
|
, leftStrings = newLeftStringsHd :: leftStrings
|
||||||
, leftLines = newLeftLinesHd :: leftLines
|
, leftLines = newLeftLinesHd :: leftLines
|
||||||
, rightStrings = strSub2 :: rightStringsTl
|
, rightStrings = strSub2 :: rightStringsTl
|
||||||
@@ -782,7 +842,9 @@ struct
|
|||||||
)
|
)
|
||||||
in
|
in
|
||||||
{ idx = curIdx + String.size strSub1
|
{ idx = curIdx + String.size strSub1
|
||||||
|
, textLength = textLength
|
||||||
, line = curLine + Vector.length newLeftLinesHd
|
, line = curLine + Vector.length newLeftLinesHd
|
||||||
|
, lineLength = lineLength
|
||||||
, leftStrings = strSub1 :: leftStrings
|
, leftStrings = strSub1 :: leftStrings
|
||||||
, leftLines = newLeftLinesHd :: leftLines
|
, leftLines = newLeftLinesHd :: leftLines
|
||||||
, rightStrings = newRightStringsHd :: rightStringsTl
|
, rightStrings = newRightStringsHd :: rightStringsTl
|
||||||
@@ -810,7 +872,9 @@ struct
|
|||||||
- String.size strSub1)
|
- String.size strSub1)
|
||||||
in
|
in
|
||||||
{ idx = curIdx + String.size strSub1 + String.size newString
|
{ idx = curIdx + String.size strSub1 + String.size newString
|
||||||
|
, textLength = textLength
|
||||||
, line = curLine + Vector.length newLines + Vector.length lineSub1
|
, line = curLine + Vector.length newLines + Vector.length lineSub1
|
||||||
|
, lineLength = lineLength
|
||||||
, leftStrings = newString :: strSub1 :: leftStrings
|
, leftStrings = newString :: strSub1 :: leftStrings
|
||||||
, leftLines = newLines :: lineSub1 :: leftLines
|
, leftLines = newLines :: lineSub1 :: leftLines
|
||||||
, rightStrings = strSub2 :: rightStringsTl
|
, rightStrings = strSub2 :: rightStringsTl
|
||||||
@@ -829,6 +893,8 @@ struct
|
|||||||
, leftLines
|
, leftLines
|
||||||
, rightStrings
|
, rightStrings
|
||||||
, rightLines
|
, rightLines
|
||||||
|
, textLength
|
||||||
|
, lineLength
|
||||||
) =
|
) =
|
||||||
case (rightStrings, rightLines) of
|
case (rightStrings, rightLines) of
|
||||||
(rightStringsHd :: rightStringsTl, rightLinesHd :: rightLinesTl) =>
|
(rightStringsHd :: rightStringsTl, rightLinesHd :: rightLinesTl) =>
|
||||||
@@ -874,6 +940,8 @@ struct
|
|||||||
, newLeftLinesHd :: leftLinesTl
|
, newLeftLinesHd :: leftLinesTl
|
||||||
, rightStringsTl
|
, rightStringsTl
|
||||||
, rightLinesTl
|
, rightLinesTl
|
||||||
|
, textLength
|
||||||
|
, lineLength
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -887,6 +955,8 @@ struct
|
|||||||
, rightLinesHd :: leftLines
|
, rightLinesHd :: leftLines
|
||||||
, rightStringsTl
|
, rightStringsTl
|
||||||
, rightLinesTl
|
, rightLinesTl
|
||||||
|
, textLength
|
||||||
|
, lineLength
|
||||||
)
|
)
|
||||||
| (_, _) =>
|
| (_, _) =>
|
||||||
moveRightAndIns
|
moveRightAndIns
|
||||||
@@ -899,6 +969,8 @@ struct
|
|||||||
, rightLinesHd :: leftLines
|
, rightLinesHd :: leftLines
|
||||||
, rightStringsTl
|
, rightStringsTl
|
||||||
, rightLinesTl
|
, rightLinesTl
|
||||||
|
, textLength
|
||||||
|
, lineLength
|
||||||
))
|
))
|
||||||
else
|
else
|
||||||
(* Need to insert in the middle of the right string's hd. *)
|
(* Need to insert in the middle of the right string's hd. *)
|
||||||
@@ -917,12 +989,16 @@ struct
|
|||||||
, rightStringsTl
|
, rightStringsTl
|
||||||
, rightLinesHd
|
, rightLinesHd
|
||||||
, rightLinesTl
|
, rightLinesTl
|
||||||
|
, textLength
|
||||||
|
, lineLength
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
| (_, _) =>
|
| (_, _) =>
|
||||||
(* Right string/line is empty. *)
|
(* Right string/line is empty. *)
|
||||||
{ idx = curIdx
|
{ idx = curIdx
|
||||||
|
, textLength = textLength
|
||||||
, line = curLine
|
, line = curLine
|
||||||
|
, lineLength = lineLength
|
||||||
, leftStrings = leftStrings
|
, leftStrings = leftStrings
|
||||||
, leftLines = leftLines
|
, leftLines = leftLines
|
||||||
, rightStrings = [newString]
|
, rightStrings = [newString]
|
||||||
@@ -939,6 +1015,8 @@ struct
|
|||||||
, leftLines
|
, leftLines
|
||||||
, rightStrings
|
, rightStrings
|
||||||
, rightLines
|
, rightLines
|
||||||
|
, textLength
|
||||||
|
, lineLength
|
||||||
) : t =
|
) : t =
|
||||||
if curIdx = idx then
|
if curIdx = idx then
|
||||||
insWhenIdxAndCurIdxAreEqual
|
insWhenIdxAndCurIdxAreEqual
|
||||||
@@ -950,6 +1028,8 @@ struct
|
|||||||
, leftLines
|
, leftLines
|
||||||
, rightStrings
|
, rightStrings
|
||||||
, rightLines
|
, rightLines
|
||||||
|
, textLength
|
||||||
|
, lineLength
|
||||||
)
|
)
|
||||||
else if idx < curIdx then
|
else if idx < curIdx then
|
||||||
moveLeftAndIns
|
moveLeftAndIns
|
||||||
@@ -962,6 +1042,8 @@ struct
|
|||||||
, leftLines
|
, leftLines
|
||||||
, rightStrings
|
, rightStrings
|
||||||
, rightLines
|
, rightLines
|
||||||
|
, textLength
|
||||||
|
, lineLength
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
(* idx > curIdx. *)
|
(* idx > curIdx. *)
|
||||||
@@ -975,11 +1057,15 @@ struct
|
|||||||
, leftLines
|
, leftLines
|
||||||
, rightStrings
|
, rightStrings
|
||||||
, rightLines
|
, rightLines
|
||||||
|
, textLength
|
||||||
|
, lineLength
|
||||||
)
|
)
|
||||||
in
|
in
|
||||||
fun insert (idx, newString, buffer: t) =
|
fun insert (idx, newString, buffer: t) =
|
||||||
let
|
let
|
||||||
val newLines = countLineBreaks newString
|
val newLines = countLineBreaks newString
|
||||||
|
val newTextLength = #textLength buffer + String.size newString
|
||||||
|
val newLineLength = #lineLength buffer + Vector.length newLines
|
||||||
in
|
in
|
||||||
ins
|
ins
|
||||||
( idx
|
( idx
|
||||||
@@ -991,6 +1077,8 @@ struct
|
|||||||
, #leftLines buffer
|
, #leftLines buffer
|
||||||
, #rightStrings buffer
|
, #rightStrings buffer
|
||||||
, #rightLines buffer
|
, #rightLines buffer
|
||||||
|
, newTextLength
|
||||||
|
, newLineLength
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user