code function that can insert into both searchList and buffer
This commit is contained in:
@@ -46,6 +46,7 @@ struct
|
|||||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
val lineStart = Cursor.vi0 (buffer, cursorIdx)
|
val lineStart = Cursor.vi0 (buffer, cursorIdx)
|
||||||
|
|
||||||
|
(* todo: update searchList based on insert *)
|
||||||
val buffer = LineGap.insert (lineStart, " ", buffer)
|
val buffer = LineGap.insert (lineStart, " ", buffer)
|
||||||
|
|
||||||
val buffer = LineGap.goToIdx (lineStart, buffer)
|
val buffer = LineGap.goToIdx (lineStart, buffer)
|
||||||
|
|||||||
@@ -538,6 +538,27 @@ struct
|
|||||||
LEAF (items, sizes)
|
LEAF (items, sizes)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun incrementBy (incBy, tree) =
|
||||||
|
case tree of
|
||||||
|
BRANCH (nodes, sizes) =>
|
||||||
|
let
|
||||||
|
val child = incrementBy (incBy, Vector.sub (nodes, 0))
|
||||||
|
val nodes = Vector.update (nodes, 0, child)
|
||||||
|
val sizes = Vector.map (fn sz => sz + incBy) sizes
|
||||||
|
in
|
||||||
|
BRANCH (nodes, sizes)
|
||||||
|
end
|
||||||
|
| LEAF (items, sizes) =>
|
||||||
|
let
|
||||||
|
val items = Vector.map
|
||||||
|
(fn {start, finish} =>
|
||||||
|
{start = start - incBy, finish = finish - incBy}
|
||||||
|
) items
|
||||||
|
val sizes = Vector.map #finish items
|
||||||
|
in
|
||||||
|
LEAF (items, sizes)
|
||||||
|
end
|
||||||
|
|
||||||
fun countDepthLoop (counter, tree) =
|
fun countDepthLoop (counter, tree) =
|
||||||
case tree of
|
case tree of
|
||||||
BRANCH (nodes, _) => countDepthLoop (counter + 1, Vector.sub (nodes, 0))
|
BRANCH (nodes, _) => countDepthLoop (counter + 1, Vector.sub (nodes, 0))
|
||||||
|
|||||||
@@ -215,4 +215,34 @@ struct
|
|||||||
tryExtendingPrevMatch
|
tryExtendingPrevMatch
|
||||||
(oldStart, buffer, searchList, dfa, ~1, 0, oldStart)
|
(oldStart, buffer, searchList, dfa, ~1, 0, oldStart)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
(* inserts into buffer and searchList both *)
|
||||||
|
fun insert (insIdx, insString, buffer, searchList, dfa) =
|
||||||
|
let
|
||||||
|
val buffer = LineGap.insert (insIdx, insString, buffer)
|
||||||
|
|
||||||
|
(* incremennt existing elements in the searchList after the insIdx
|
||||||
|
* by the length of the string that was just inserted *)
|
||||||
|
val searchList =
|
||||||
|
let
|
||||||
|
val searchListLeft = PersistentVector.splitLeft (insIdx, searchList)
|
||||||
|
val searchListRight = PersistentVector.splitRight (insIdx, searchList)
|
||||||
|
val searchListRight =
|
||||||
|
PersistentVector.incrementBy (String.size insString, searchList)
|
||||||
|
in
|
||||||
|
PersistentVector.merge (searchListLeft, searchListRight)
|
||||||
|
end
|
||||||
|
|
||||||
|
(* start looking for new matches from the previous match *)
|
||||||
|
val oldStart = PersistentVector.prevMatch (insIdx, searchList, 1)
|
||||||
|
in
|
||||||
|
if Vector.length dfa = 0 then
|
||||||
|
(buffer, searchList)
|
||||||
|
else if oldStart >= insIdx orelse oldStart = ~1 then
|
||||||
|
(* no previous match, so try searching for a match from start of buffer *)
|
||||||
|
insertUntilMatch (0, buffer, searchList, dfa, 0, 0, ~1)
|
||||||
|
else
|
||||||
|
tryExtendingPrevMatch
|
||||||
|
(oldStart, buffer, searchList, dfa, ~1, 0, oldStart)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user