handle edge case in line_gap.sml when deleting to the left: we sometimes need to delete to the end of the string, so add a branch handling that case
This commit is contained in:
177
src/line_gap.sml
177
src/line_gap.sml
@@ -1971,79 +1971,128 @@ struct
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
else if prevIdx < start then
|
else if prevIdx < start then
|
||||||
(* We want to delete in the middle of leftStringsHd.
|
if finish >= curIdx then
|
||||||
* We also have to delete in the middle of leftLinesHd in order to
|
(* delete from end of string *)
|
||||||
* do this. *)
|
let
|
||||||
let
|
val oldNodeTextLength = String.size leftStringsHd
|
||||||
val oldNodeTextLength = String.size leftStringsHd
|
val oldNodeLineLength = Vector.length leftLinesHd
|
||||||
val oldNodeLineLength = Vector.length leftLinesHd
|
|
||||||
|
|
||||||
val sub1Length = start - prevIdx
|
val sub1Length = start - prevIdx
|
||||||
val sub1 = String.substring (leftStringsHd, 0, sub1Length)
|
val sub1 = String.substring (leftStringsHd, 0, sub1Length)
|
||||||
val sub2Start = finish - prevIdx
|
val sub1Lines =
|
||||||
val sub2 = String.substring
|
if Vector.length leftLinesHd > 0 then
|
||||||
( leftStringsHd
|
let
|
||||||
, sub2Start
|
val midpoint = binSearch
|
||||||
, String.size leftStringsHd - sub2Start
|
(String.size sub1 - 1, leftLinesHd)
|
||||||
)
|
in
|
||||||
|
if midpoint >= 0 then
|
||||||
|
let
|
||||||
|
val slice = VectorSlice.slice
|
||||||
|
(leftLinesHd, 0, SOME (midpoint + 1))
|
||||||
|
in
|
||||||
|
VectorSlice.vector slice
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Vector.fromList []
|
||||||
|
end
|
||||||
|
else
|
||||||
|
leftLinesHd
|
||||||
|
val newNodeTextLength = String.size sub1
|
||||||
|
val textLengthDifference =
|
||||||
|
oldNodeTextLength - newNodeTextLength
|
||||||
|
val textLength = textLength - textLengthDifference
|
||||||
|
|
||||||
val sub1Lines =
|
val newNodeLineLength = Vector.length sub1Lines
|
||||||
if Vector.length leftLinesHd > 0 then
|
val lineLengthDifference =
|
||||||
|
oldNodeLineLength - newNodeLineLength
|
||||||
|
val lineLength = lineLength - lineLengthDifference
|
||||||
|
in
|
||||||
|
{ idx = prevIdx + String.size sub1
|
||||||
|
, line =
|
||||||
|
(curLine - Vector.length leftLinesHd)
|
||||||
|
+ Vector.length sub1Lines
|
||||||
|
, leftStrings = sub1 :: leftStringsTl
|
||||||
|
, leftLines = sub1Lines :: leftLinesTl
|
||||||
|
, rightStrings = rightStrings
|
||||||
|
, rightLines = rightLines
|
||||||
|
, textLength = textLength
|
||||||
|
, lineLength = lineLength
|
||||||
|
}
|
||||||
|
end
|
||||||
|
else
|
||||||
|
(* We want to delete in the middle of leftStringsHd.
|
||||||
|
* We also have to delete in the middle of leftLinesHd in order to
|
||||||
|
* do this. *)
|
||||||
|
let
|
||||||
|
val oldNodeTextLength = String.size leftStringsHd
|
||||||
|
val oldNodeLineLength = Vector.length leftLinesHd
|
||||||
|
|
||||||
|
val sub1Length = start - prevIdx
|
||||||
|
val sub1 = String.substring (leftStringsHd, 0, sub1Length)
|
||||||
|
val sub2Start = finish - prevIdx
|
||||||
|
val sub2 = String.substring
|
||||||
|
( leftStringsHd
|
||||||
|
, sub2Start
|
||||||
|
, String.size leftStringsHd - sub2Start
|
||||||
|
)
|
||||||
|
|
||||||
|
val sub1Lines =
|
||||||
|
if Vector.length leftLinesHd > 0 then
|
||||||
|
let
|
||||||
|
val midpoint = binSearch
|
||||||
|
(String.size sub1 - 1, leftLinesHd)
|
||||||
|
in
|
||||||
|
if midpoint >= 0 then
|
||||||
|
let
|
||||||
|
val slice = VectorSlice.slice
|
||||||
|
(leftLinesHd, 0, SOME (midpoint + 1))
|
||||||
|
in
|
||||||
|
VectorSlice.vector slice
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Vector.fromList []
|
||||||
|
end
|
||||||
|
else
|
||||||
|
leftLinesHd
|
||||||
|
|
||||||
|
val sub2Lines =
|
||||||
let
|
let
|
||||||
val midpoint = binSearch
|
val midpoint = forwardBinSearch (sub2Start, leftLinesHd)
|
||||||
(String.size sub1 - 1, leftLinesHd)
|
|
||||||
in
|
in
|
||||||
if midpoint >= 0 then
|
if midpoint < Vector.length leftLinesHd then
|
||||||
let
|
Vector.tabulate
|
||||||
val slice = VectorSlice.slice
|
( Vector.length leftLinesHd - midpoint
|
||||||
(leftLinesHd, 0, SOME (midpoint + 1))
|
, fn idx =>
|
||||||
in
|
Vector.sub (leftLinesHd, idx + midpoint)
|
||||||
VectorSlice.vector slice
|
- sub2Start
|
||||||
end
|
)
|
||||||
else
|
else
|
||||||
Vector.fromList []
|
Vector.fromList []
|
||||||
end
|
end
|
||||||
else
|
|
||||||
leftLinesHd
|
|
||||||
|
|
||||||
val sub2Lines =
|
val newNodeTextLength = String.size sub1 + String.size sub2
|
||||||
let
|
val textLengthDifference =
|
||||||
val midpoint = forwardBinSearch (sub2Start, leftLinesHd)
|
oldNodeTextLength - newNodeTextLength
|
||||||
in
|
val textLength = textLength - textLengthDifference
|
||||||
if midpoint < Vector.length leftLinesHd then
|
|
||||||
Vector.tabulate
|
|
||||||
( Vector.length leftLinesHd - midpoint
|
|
||||||
, fn idx =>
|
|
||||||
Vector.sub (leftLinesHd, idx + midpoint)
|
|
||||||
- sub2Start
|
|
||||||
)
|
|
||||||
else
|
|
||||||
Vector.fromList []
|
|
||||||
end
|
|
||||||
|
|
||||||
val newNodeTextLength = String.size sub1 + String.size sub2
|
val newNodeLineLength =
|
||||||
val textLengthDifference =
|
Vector.length sub1Lines + Vector.length sub2Lines
|
||||||
oldNodeTextLength - newNodeTextLength
|
val lineLengthDifference =
|
||||||
val textLength = textLength - textLengthDifference
|
oldNodeLineLength - newNodeLineLength
|
||||||
|
val lineLength = lineLength - lineLengthDifference
|
||||||
val newNodeLineLength =
|
in
|
||||||
Vector.length sub1Lines + Vector.length sub2Lines
|
{ idx = prevIdx + String.size sub1
|
||||||
val lineLengthDifference =
|
, line =
|
||||||
oldNodeLineLength - newNodeLineLength
|
(curLine - Vector.length leftLinesHd)
|
||||||
val lineLength = lineLength - lineLengthDifference
|
+ Vector.length sub1Lines
|
||||||
in
|
, leftStrings = sub1 :: leftStringsTl
|
||||||
{ idx = prevIdx + String.size sub1
|
, leftLines = sub1Lines :: leftLinesTl
|
||||||
, line =
|
, rightStrings = sub2 :: rightStrings
|
||||||
(curLine - Vector.length leftLinesHd)
|
, rightLines = sub2Lines :: rightLines
|
||||||
+ Vector.length sub1Lines
|
, textLength = textLength
|
||||||
, leftStrings = sub1 :: leftStringsTl
|
, lineLength = lineLength
|
||||||
, leftLines = sub1Lines :: leftLinesTl
|
}
|
||||||
, rightStrings = sub2 :: rightStrings
|
end
|
||||||
, rightLines = sub2Lines :: rightLines
|
|
||||||
, textLength = textLength
|
|
||||||
, lineLength = lineLength
|
|
||||||
}
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
(* prevIdx = start
|
(* prevIdx = start
|
||||||
* We want to delete from the start of this string and stop. *)
|
* We want to delete from the start of this string and stop. *)
|
||||||
|
|||||||
Reference in New Issue
Block a user