add function in PersistentVector to insert a match while keeping same absolute indices (to be used when a new match appears after a deletion)
This commit is contained in:
@@ -722,13 +722,20 @@ struct
|
|||||||
else
|
else
|
||||||
let
|
let
|
||||||
val finish = start + length
|
val finish = start + length
|
||||||
|
|
||||||
val matchBeforeStart = prevMatch (start, tree, 1)
|
val matchBeforeStart = prevMatch (start, tree, 1)
|
||||||
val matchBeforeStart =
|
val matchBeforeStart =
|
||||||
if matchBeforeStart >= start then
|
if matchBeforeStart >= start then
|
||||||
~1
|
~1
|
||||||
else
|
else
|
||||||
matchBeforeStart
|
matchBeforeStart
|
||||||
|
|
||||||
val matchAfterFinish = nextMatch (finish, tree, 1)
|
val matchAfterFinish = nextMatch (finish, tree, 1)
|
||||||
|
val matchAfterFinish =
|
||||||
|
if matchAfterFinish < finish then
|
||||||
|
~1
|
||||||
|
else
|
||||||
|
matchAfterFinish
|
||||||
in
|
in
|
||||||
if matchBeforeStart = ~1 andalso matchAfterFinish = ~1 then
|
if matchBeforeStart = ~1 andalso matchAfterFinish = ~1 then
|
||||||
empty
|
empty
|
||||||
@@ -789,6 +796,36 @@ struct
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
(* Usually, when inserting, we want the absolute metadata
|
||||||
|
* to be adjusted appropriately.
|
||||||
|
* An insertion should cause the absolute metadata to increment.
|
||||||
|
* However, we sometimes want to insert a match without adjusting
|
||||||
|
* the absolute metadata in this way.
|
||||||
|
* We want to do this when deleting some part of the buffer
|
||||||
|
* would cause a new match to be found, for example. *)
|
||||||
|
fun insertMatchKeepingAbsoluteInddices (start, finish, tree) =
|
||||||
|
let
|
||||||
|
val matchAfterFinish = nextMatch (finish, tree, 1)
|
||||||
|
in
|
||||||
|
if matchAfterFinish <= finish then
|
||||||
|
(* no match after the 'finish', so we just append *)
|
||||||
|
append (start, finish, tree)
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val left = splitLeft (start, tree)
|
||||||
|
val right = splitRight (finish, tree)
|
||||||
|
|
||||||
|
val left = append (start, finish, tree)
|
||||||
|
|
||||||
|
val rightStartRelative = getStartIdx right
|
||||||
|
val rightStartAbsolute = rightStartRelative + finish
|
||||||
|
val difference = rightStartAbsolute - matchAfterFinish
|
||||||
|
val right = decrementBy (difference, right)
|
||||||
|
in
|
||||||
|
merge (left, right)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
(* functions only for testing *)
|
(* functions only for testing *)
|
||||||
fun fromListLoop (lst, acc) =
|
fun fromListLoop (lst, acc) =
|
||||||
case lst of
|
case lst of
|
||||||
|
|||||||
Reference in New Issue
Block a user