initial implementation of building search list
This commit is contained in:
@@ -98,4 +98,28 @@ struct
|
|||||||
, startLine = startLine
|
, startLine = startLine
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun searchListAndBuffer (app: app_type, newSearchList, newBuffer) =
|
||||||
|
let
|
||||||
|
val
|
||||||
|
{ searchList = _
|
||||||
|
, buffer = _
|
||||||
|
, mode
|
||||||
|
, searchString
|
||||||
|
, cursorIdx
|
||||||
|
, windowWidth
|
||||||
|
, windowHeight
|
||||||
|
, startLine
|
||||||
|
} = app
|
||||||
|
in
|
||||||
|
{ searchList = newSearchList
|
||||||
|
, buffer = newBuffer
|
||||||
|
, mode = mode
|
||||||
|
, searchString = searchString
|
||||||
|
, cursorIdx = cursorIdx
|
||||||
|
, windowWidth = windowWidth
|
||||||
|
, windowHeight = windowHeight
|
||||||
|
, startLine = startLine
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
81
fcore/build-search-list.sml
Normal file
81
fcore/build-search-list.sml
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
structure BuildSearchList =
|
||||||
|
struct
|
||||||
|
fun helpNextMatch (idx, hd, tl, absIdx, searchString, matchedChrs) =
|
||||||
|
if idx = String.size hd then
|
||||||
|
case tl of
|
||||||
|
tlhd :: tltl =>
|
||||||
|
helpNextMatch (0, tlhd, tltl, absIdx, searchString, matchedChrs)
|
||||||
|
| [] =>
|
||||||
|
NONE
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val hdChr = String.sub (hd, idx)
|
||||||
|
val searchChr = String.sub (searchString, matchedChrs)
|
||||||
|
in
|
||||||
|
if hdChr = searchChr then
|
||||||
|
if matchedChrs + 1 = String.size searchString then
|
||||||
|
let
|
||||||
|
val matchedIdx = absIdx - String.size searchString - 1
|
||||||
|
in
|
||||||
|
SOME matchedIdx
|
||||||
|
end
|
||||||
|
else
|
||||||
|
helpNextMatch
|
||||||
|
(idx + 1, hd, tl, absIdx + 1, searchString, matchedChrs + 1)
|
||||||
|
else
|
||||||
|
helpNextMatch (idx + 1, hd, tl, absIdx + 1, searchString, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun nextMatch (bufferIdx, absIdx, rightStrings, searchString) =
|
||||||
|
case rightStrings of
|
||||||
|
hd :: tl =>
|
||||||
|
let
|
||||||
|
val strIdx = absIdx - bufferIdx
|
||||||
|
in
|
||||||
|
if strIdx < String.size hd then
|
||||||
|
helpNextMatch (strIdx, hd, tl, absIdx, searchString, 0)
|
||||||
|
else
|
||||||
|
(case tl of
|
||||||
|
tlhd :: tltl =>
|
||||||
|
let
|
||||||
|
val strIdx = strIdx - String.size hd
|
||||||
|
in
|
||||||
|
helpNextMatch (strIdx, tlhd, tltl, absIdx, searchString, 0)
|
||||||
|
end
|
||||||
|
| [] => NONE)
|
||||||
|
end
|
||||||
|
| [] => NONE
|
||||||
|
|
||||||
|
fun helpBuild (app, origIdx, absIdx, buffer, searchString, searchList) =
|
||||||
|
let
|
||||||
|
val buffer = LineGap.goToIdx (absIdx, buffer)
|
||||||
|
val {idx = bufferIdx, rightStrings, ...} = buffer
|
||||||
|
in
|
||||||
|
case nextMatch (bufferIdx, absIdx, rightStrings, searchString) of
|
||||||
|
SOME matchedIdx =>
|
||||||
|
let
|
||||||
|
val searchList = SearchList.append (matchedIdx, searchList)
|
||||||
|
in
|
||||||
|
helpBuild
|
||||||
|
(app, origIdx, matchedIdx, buffer, searchString, searchList)
|
||||||
|
end
|
||||||
|
| NONE =>
|
||||||
|
let
|
||||||
|
val buffer = LineGap.goToIdx (origIdx, buffer)
|
||||||
|
val searchList = SearchList.goToNum (origIdx, searchList)
|
||||||
|
in
|
||||||
|
AppWith.searchListAndBuffer (app, searchList, buffer)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
fun build (app, cursorIdx, buffer, searchString) =
|
||||||
|
if String.size searchString > 0 then
|
||||||
|
let
|
||||||
|
val buffer = LineGap.goToStart buffer
|
||||||
|
in
|
||||||
|
helpBuild
|
||||||
|
(app, cursorIdx, 0, buffer, searchString, SearchList.empty)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
app
|
||||||
|
end
|
||||||
@@ -2,8 +2,12 @@ signature SEARCH_LIST =
|
|||||||
sig
|
sig
|
||||||
type t = {left: int vector list, right: int vector list}
|
type t = {left: int vector list, right: int vector list}
|
||||||
val empty: t
|
val empty: t
|
||||||
|
|
||||||
val insert: int * t -> t
|
val insert: int * t -> t
|
||||||
|
val append: int * t -> t
|
||||||
val delete: int * int * t -> t
|
val delete: int * int * t -> t
|
||||||
|
|
||||||
|
val goToNum: int * t -> t
|
||||||
val mapFromNum: int * int * t -> t
|
val mapFromNum: int * int * t -> t
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -148,6 +152,13 @@ struct
|
|||||||
else insLeft (new, left, right)
|
else insLeft (new, left, right)
|
||||||
| [] => insLeft (new, left, right)
|
| [] => insLeft (new, left, right)
|
||||||
|
|
||||||
|
fun helpAppend (new, left, right) =
|
||||||
|
case right of
|
||||||
|
hd :: tl => helpAppend (new, joinEndOfLeft (hd, left), tl)
|
||||||
|
| [] => {left = joinEndOfLeft (Vector.fromList [new], left), right = right}
|
||||||
|
|
||||||
|
fun append (new, {left, right}: t) = helpAppend (new, left, right)
|
||||||
|
|
||||||
fun helpGoToNumLeft (num, left, right) =
|
fun helpGoToNumLeft (num, left, right) =
|
||||||
case left of
|
case left of
|
||||||
hd :: tl =>
|
hd :: tl =>
|
||||||
|
|||||||
Reference in New Issue
Block a user