code functions to build search list from a range in the buffer (not searching for every single match, but searching for visible matches on user's window)
This commit is contained in:
@@ -668,7 +668,7 @@ struct
|
|||||||
app
|
app
|
||||||
|
|
||||||
val buffer = LineGap.delete (0, cursorIdx, buffer)
|
val buffer = LineGap.delete (0, cursorIdx, buffer)
|
||||||
val (buffer, searchList) = SearchList.build (buffer, searchString)
|
val searchList = SearchList.empty
|
||||||
|
|
||||||
val buffer = LineGap.goToEnd buffer
|
val buffer = LineGap.goToEnd buffer
|
||||||
val initialMsg = [SEARCH (buffer, #searchString app)]
|
val initialMsg = [SEARCH (buffer, #searchString app)]
|
||||||
|
|||||||
@@ -39,30 +39,20 @@ struct
|
|||||||
loopSearch (pos - 1, hd, absIdx - 1, tl, acc, searchString)
|
loopSearch (pos - 1, hd, absIdx - 1, tl, acc, searchString)
|
||||||
end
|
end
|
||||||
|
|
||||||
(* Prerequisite: move buffer/LineGap to end *)
|
|
||||||
fun search (buffer: LineGap.t, searchString) =
|
fun search (buffer: LineGap.t, searchString) =
|
||||||
if String.size searchString = 0 then
|
let
|
||||||
empty
|
val {leftStrings, idx = absIdx, ...} = buffer
|
||||||
else
|
in
|
||||||
let
|
case leftStrings of
|
||||||
val {leftStrings, idx = absIdx, ...} = buffer
|
hd :: tl =>
|
||||||
in
|
loopSearch (String.size hd - 1, hd, absIdx - 1, tl, [], searchString)
|
||||||
case leftStrings of
|
| [] => empty
|
||||||
hd :: tl =>
|
end
|
||||||
loopSearch
|
|
||||||
(String.size hd - 1, hd, absIdx - 1, tl, [], searchString)
|
|
||||||
| [] => empty
|
|
||||||
end
|
|
||||||
|
|
||||||
|
(* Prerequisite: move buffer/LineGap to end *)
|
||||||
fun build (buffer, searchString) =
|
fun build (buffer, searchString) =
|
||||||
if String.size searchString > 0 then
|
if String.size searchString > 0 then search (buffer, searchString)
|
||||||
let
|
else empty
|
||||||
val searchList = search (buffer, searchString)
|
|
||||||
in
|
|
||||||
searchList
|
|
||||||
end
|
|
||||||
else
|
|
||||||
empty
|
|
||||||
|
|
||||||
fun loopNextMatch (pos, searchList, count) =
|
fun loopNextMatch (pos, searchList, count) =
|
||||||
if count = 0 then
|
if count = 0 then
|
||||||
@@ -111,4 +101,87 @@ struct
|
|||||||
in
|
in
|
||||||
loopPrevMatch (pos, searchList, count)
|
loopPrevMatch (pos, searchList, count)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun rangeSearchStep (pos, hd, absIdx, tl, acc, searchPos, searchString, low) =
|
||||||
|
if searchPos < 0 then
|
||||||
|
(absIdx + 1) :: acc
|
||||||
|
else if absIdx < low then
|
||||||
|
acc
|
||||||
|
else if pos < 0 then
|
||||||
|
case tl of
|
||||||
|
hd :: tl =>
|
||||||
|
rangeSearchStep
|
||||||
|
( String.size hd - 1
|
||||||
|
, hd
|
||||||
|
, absIdx
|
||||||
|
, tl
|
||||||
|
, acc
|
||||||
|
, searchPos
|
||||||
|
, searchString
|
||||||
|
, low
|
||||||
|
)
|
||||||
|
| [] => acc
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val bufferChr = String.sub (hd, pos)
|
||||||
|
val searchChr = String.sub (searchString, searchPos)
|
||||||
|
in
|
||||||
|
if bufferChr = searchChr then
|
||||||
|
rangeSearchStep
|
||||||
|
(pos - 1, hd, absIdx - 1, tl, acc, searchPos - 1, searchString, low)
|
||||||
|
else
|
||||||
|
acc
|
||||||
|
end
|
||||||
|
|
||||||
|
fun loopRange (pos, hd, absIdx, tl, acc, searchString, low) =
|
||||||
|
if absIdx < low then
|
||||||
|
Vector.fromList acc
|
||||||
|
else if pos < 0 then
|
||||||
|
case tl of
|
||||||
|
hd :: tl =>
|
||||||
|
loopRange (String.size hd - 1, hd, absIdx, tl, acc, searchString, low)
|
||||||
|
| [] => Vector.fromList acc
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val acc = rangeSearchStep
|
||||||
|
( pos
|
||||||
|
, hd
|
||||||
|
, absIdx
|
||||||
|
, tl
|
||||||
|
, acc
|
||||||
|
, String.size searchString - 1
|
||||||
|
, searchString
|
||||||
|
, low
|
||||||
|
)
|
||||||
|
in
|
||||||
|
loopRange (pos - 1, hd, absIdx - 1, tl, acc, searchString, low)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun searchRange (buffer: LineGap.t, searchString, low) =
|
||||||
|
let
|
||||||
|
val {rightStrings, leftStrings, idx = absIdx, ...} = buffer
|
||||||
|
in
|
||||||
|
case rightStrings of
|
||||||
|
hd :: _ =>
|
||||||
|
let
|
||||||
|
val pos = String.size hd - 1
|
||||||
|
val absIdx = absIdx + String.size hd - 1
|
||||||
|
in
|
||||||
|
loopRange (pos, hd, absIdx, leftStrings, [], searchString, low)
|
||||||
|
end
|
||||||
|
| [] =>
|
||||||
|
(case leftStrings of
|
||||||
|
hd :: tl =>
|
||||||
|
let
|
||||||
|
val pos = String.size hd - 1
|
||||||
|
val absIdx = absIdx - 1
|
||||||
|
in
|
||||||
|
loopRange (pos, hd, absIdx, tl, [], searchString, low)
|
||||||
|
end
|
||||||
|
| [] => empty)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun buildRange (buffer, searchString, low) =
|
||||||
|
if String.size searchString > 0 then searchRange (buffer, searchString, low)
|
||||||
|
else empty
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -68,9 +68,10 @@ struct
|
|||||||
(* todo: remove temp line below which tests search list *)
|
(* todo: remove temp line below which tests search list *)
|
||||||
val app =
|
val app =
|
||||||
let
|
let
|
||||||
|
val buffer = #buffer app
|
||||||
|
val buffer = LineGap.goToEnd buffer
|
||||||
val searchString = "val "
|
val searchString = "val "
|
||||||
val (buffer, searchList) =
|
val searchList = SearchList.build (buffer, searchString)
|
||||||
SearchList.build (#buffer app, searchString)
|
|
||||||
val buffer = LineGap.goToStart buffer
|
val buffer = LineGap.goToStart buffer
|
||||||
in
|
in
|
||||||
AppWith.searchList (app, searchList, buffer, searchString)
|
AppWith.searchList (app, searchList, buffer, searchString)
|
||||||
|
|||||||
Reference in New Issue
Block a user