add searchCursorIdx field specific to NORMAL_SEARCH_MODE which we will later use to keep track of where to add/remove characters in the in-progress searchString from
This commit is contained in:
@@ -6,14 +6,8 @@ struct
|
||||
open InputMsg
|
||||
|
||||
fun switchToNormalSearchMode (app: app_type) =
|
||||
let
|
||||
val mode =
|
||||
NORMAL_SEARCH_MODE
|
||||
{searchString = "", tempSearchList = Vector.fromList []}
|
||||
in
|
||||
NormalSearchFinish.onSearchChanged
|
||||
(app, "", Vector.fromList [], #buffer app)
|
||||
end
|
||||
NormalSearchFinish.onSearchChanged
|
||||
(app, "", Vector.fromList [], 0, #buffer app)
|
||||
|
||||
fun getNumLength (pos, str) =
|
||||
if pos = String.size str then
|
||||
|
||||
@@ -2,14 +2,17 @@ structure NormalSearchFinish =
|
||||
struct
|
||||
open AppType
|
||||
|
||||
fun onSearchChanged (app: app_type, searchString, tempSearchList, buffer) =
|
||||
fun onSearchChanged
|
||||
(app: app_type, searchString, tempSearchList, searchCursorIdx, buffer) =
|
||||
let
|
||||
open DrawMsg
|
||||
|
||||
val {buffer, cursorIdx, startLine, windowWidth, windowHeight, ...} = app
|
||||
val mode =
|
||||
NORMAL_SEARCH_MODE
|
||||
{searchString = searchString, tempSearchList = tempSearchList}
|
||||
val mode = NORMAL_SEARCH_MODE
|
||||
{ searchString = searchString
|
||||
, tempSearchList = tempSearchList
|
||||
, searchCursorIdx = searchCursorIdx
|
||||
}
|
||||
|
||||
val floatWindowWidth = Real32.fromInt windowWidth
|
||||
val floatWindowHeight = Real32.fromInt windowHeight
|
||||
|
||||
@@ -4,19 +4,30 @@ struct
|
||||
open InputMsg
|
||||
open MailboxType
|
||||
|
||||
fun addChr (app: app_type, searchString, chr) =
|
||||
fun addChr (app: app_type, searchString, searchCurosrIdx, chr) =
|
||||
let
|
||||
val {cursorIdx, buffer, ...} = app
|
||||
|
||||
val c = String.implode [chr]
|
||||
val searchString = searchString ^ c
|
||||
val searchString =
|
||||
if searchCurosrIdx = String.size searchString then
|
||||
searchString ^ c
|
||||
else
|
||||
let
|
||||
val sub1 = Substring.extract (searchString, 0, SOME searchCurosrIdx)
|
||||
val sub2 = Substring.full c
|
||||
val sub3 = Substring.extract (searchString, searchCurosrIdx, NONE)
|
||||
in
|
||||
Substring.concat [sub1, sub2, sub3]
|
||||
end
|
||||
val searchCurosrIdx = searchCurosrIdx + 1
|
||||
|
||||
val buffer = LineGap.goToIdx (cursorIdx - 1111, buffer)
|
||||
val tempSearchList =
|
||||
SearchList.buildRange (buffer, searchString, cursorIdx + 1111)
|
||||
in
|
||||
NormalSearchFinish.onSearchChanged
|
||||
(app, searchString, tempSearchList, buffer)
|
||||
(app, searchString, tempSearchList, searchCurosrIdx, buffer)
|
||||
end
|
||||
|
||||
(* return to normal mode, keeping the same searchString and searchList
|
||||
@@ -67,9 +78,9 @@ struct
|
||||
fun backspace (app: app_type, searchString, tempSearchList) =
|
||||
raise Fail "normal-search-mode: KEY_BACKSPACE unimplemented"
|
||||
|
||||
fun update (app, {searchString, tempSearchList}, msg, time) =
|
||||
fun update (app, {searchString, tempSearchList, searchCursorIdx}, msg, time) =
|
||||
case msg of
|
||||
CHAR_EVENT chr => addChr (app, searchString, chr)
|
||||
CHAR_EVENT chr => addChr (app, searchString, searchCursorIdx, chr)
|
||||
| KEY_BACKSPACE => backspace (app, searchString, tempSearchList)
|
||||
| KEY_ESC => exitToNormalMode app
|
||||
| KEY_ENTER => saveSearch (app, searchString, tempSearchList)
|
||||
|
||||
Reference in New Issue
Block a user