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:
@@ -2,7 +2,8 @@ structure AppType =
|
|||||||
struct
|
struct
|
||||||
datatype mode =
|
datatype mode =
|
||||||
NORMAL_MODE of string
|
NORMAL_MODE of string
|
||||||
| NORMAL_SEARCH_MODE of {searchString: string, tempSearchList: int vector}
|
| NORMAL_SEARCH_MODE of {searchString: string, tempSearchList: int vector,
|
||||||
|
searchCursorIdx: int}
|
||||||
|
|
||||||
type app_type =
|
type app_type =
|
||||||
{ mode: mode
|
{ mode: mode
|
||||||
|
|||||||
@@ -6,14 +6,8 @@ struct
|
|||||||
open InputMsg
|
open InputMsg
|
||||||
|
|
||||||
fun switchToNormalSearchMode (app: app_type) =
|
fun switchToNormalSearchMode (app: app_type) =
|
||||||
let
|
NormalSearchFinish.onSearchChanged
|
||||||
val mode =
|
(app, "", Vector.fromList [], 0, #buffer app)
|
||||||
NORMAL_SEARCH_MODE
|
|
||||||
{searchString = "", tempSearchList = Vector.fromList []}
|
|
||||||
in
|
|
||||||
NormalSearchFinish.onSearchChanged
|
|
||||||
(app, "", Vector.fromList [], #buffer app)
|
|
||||||
end
|
|
||||||
|
|
||||||
fun getNumLength (pos, str) =
|
fun getNumLength (pos, str) =
|
||||||
if pos = String.size str then
|
if pos = String.size str then
|
||||||
|
|||||||
@@ -2,14 +2,17 @@ structure NormalSearchFinish =
|
|||||||
struct
|
struct
|
||||||
open AppType
|
open AppType
|
||||||
|
|
||||||
fun onSearchChanged (app: app_type, searchString, tempSearchList, buffer) =
|
fun onSearchChanged
|
||||||
|
(app: app_type, searchString, tempSearchList, searchCursorIdx, buffer) =
|
||||||
let
|
let
|
||||||
open DrawMsg
|
open DrawMsg
|
||||||
|
|
||||||
val {buffer, cursorIdx, startLine, windowWidth, windowHeight, ...} = app
|
val {buffer, cursorIdx, startLine, windowWidth, windowHeight, ...} = app
|
||||||
val mode =
|
val mode = NORMAL_SEARCH_MODE
|
||||||
NORMAL_SEARCH_MODE
|
{ searchString = searchString
|
||||||
{searchString = searchString, tempSearchList = tempSearchList}
|
, tempSearchList = tempSearchList
|
||||||
|
, searchCursorIdx = searchCursorIdx
|
||||||
|
}
|
||||||
|
|
||||||
val floatWindowWidth = Real32.fromInt windowWidth
|
val floatWindowWidth = Real32.fromInt windowWidth
|
||||||
val floatWindowHeight = Real32.fromInt windowHeight
|
val floatWindowHeight = Real32.fromInt windowHeight
|
||||||
|
|||||||
@@ -4,19 +4,30 @@ struct
|
|||||||
open InputMsg
|
open InputMsg
|
||||||
open MailboxType
|
open MailboxType
|
||||||
|
|
||||||
fun addChr (app: app_type, searchString, chr) =
|
fun addChr (app: app_type, searchString, searchCurosrIdx, chr) =
|
||||||
let
|
let
|
||||||
val {cursorIdx, buffer, ...} = app
|
val {cursorIdx, buffer, ...} = app
|
||||||
|
|
||||||
val c = String.implode [chr]
|
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 buffer = LineGap.goToIdx (cursorIdx - 1111, buffer)
|
||||||
val tempSearchList =
|
val tempSearchList =
|
||||||
SearchList.buildRange (buffer, searchString, cursorIdx + 1111)
|
SearchList.buildRange (buffer, searchString, cursorIdx + 1111)
|
||||||
in
|
in
|
||||||
NormalSearchFinish.onSearchChanged
|
NormalSearchFinish.onSearchChanged
|
||||||
(app, searchString, tempSearchList, buffer)
|
(app, searchString, tempSearchList, searchCurosrIdx, buffer)
|
||||||
end
|
end
|
||||||
|
|
||||||
(* return to normal mode, keeping the same searchString and searchList
|
(* return to normal mode, keeping the same searchString and searchList
|
||||||
@@ -67,9 +78,9 @@ struct
|
|||||||
fun backspace (app: app_type, searchString, tempSearchList) =
|
fun backspace (app: app_type, searchString, tempSearchList) =
|
||||||
raise Fail "normal-search-mode: KEY_BACKSPACE unimplemented"
|
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
|
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_BACKSPACE => backspace (app, searchString, tempSearchList)
|
||||||
| KEY_ESC => exitToNormalMode app
|
| KEY_ESC => exitToNormalMode app
|
||||||
| KEY_ENTER => saveSearch (app, searchString, tempSearchList)
|
| KEY_ENTER => saveSearch (app, searchString, tempSearchList)
|
||||||
|
|||||||
Reference in New Issue
Block a user