add functionality to return from NORMAL_SEARCH_MODE back to NORMAL_MODE, saving new search string and new search list
This commit is contained in:
40
fcore/normal-mode/normal-search-mode-with.sml
Normal file
40
fcore/normal-mode/normal-search-mode-with.sml
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
structure NormalSearchModeWith =
|
||||||
|
struct
|
||||||
|
open AppType
|
||||||
|
|
||||||
|
fun returnToNormalMode
|
||||||
|
( app: app_type
|
||||||
|
, newBuffer
|
||||||
|
, newSearchString
|
||||||
|
, newSearchList
|
||||||
|
, newStartLine
|
||||||
|
, newMode
|
||||||
|
, newMsgs
|
||||||
|
) =
|
||||||
|
let
|
||||||
|
val
|
||||||
|
{ mode = _
|
||||||
|
, buffer = _
|
||||||
|
, searchString = _
|
||||||
|
, searchList = _
|
||||||
|
, startLine = _
|
||||||
|
, msgs = _
|
||||||
|
, bufferModifyTime
|
||||||
|
, windowWidth
|
||||||
|
, windowHeight
|
||||||
|
, cursorIdx
|
||||||
|
} = app
|
||||||
|
in
|
||||||
|
{ mode = newMode
|
||||||
|
, buffer = newBuffer
|
||||||
|
, searchString = newSearchString
|
||||||
|
, searchList = newSearchList
|
||||||
|
, startLine = newStartLine
|
||||||
|
, bufferModifyTime = bufferModifyTime
|
||||||
|
, msgs = newMsgs
|
||||||
|
, windowWidth = windowWidth
|
||||||
|
, windowHeight = windowHeight
|
||||||
|
, cursorIdx = cursorIdx
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -2,9 +2,10 @@ structure NormalSearchMode =
|
|||||||
struct
|
struct
|
||||||
open AppType
|
open AppType
|
||||||
open InputMsg
|
open InputMsg
|
||||||
|
open MailboxType
|
||||||
|
|
||||||
(* todo: redraw based on results of tempSearchList *)
|
(* todo: redraw based on results of tempSearchList *)
|
||||||
fun parseChr (app: app_type, searchString, chr) =
|
fun addChr (app: app_type, searchString, chr) =
|
||||||
let
|
let
|
||||||
val c = String.implode [chr]
|
val c = String.implode [chr]
|
||||||
val searchString = searchString ^ c
|
val searchString = searchString ^ c
|
||||||
@@ -21,13 +22,50 @@ struct
|
|||||||
NormalModeWith.mode (app, mode, [])
|
NormalModeWith.mode (app, mode, [])
|
||||||
end
|
end
|
||||||
|
|
||||||
(* todo: switch to normal mode, save tempSearchList and searchString,
|
(* save search string and tempSearchList and return to normal mode *)
|
||||||
* and redraw *)
|
fun finishSearch (app: app_type, searchString, tempSearchList) =
|
||||||
fun finishSearch (app: app_type, searchString, tempSearchList) = app
|
let
|
||||||
|
val {buffer, cursorIdx, windowWidth, windowHeight, startLine, ...} = app
|
||||||
|
val buffer = LineGap.goToStart buffer
|
||||||
|
val initialMsg = [SEARCH (buffer, searchString)]
|
||||||
|
|
||||||
|
(* move LineGap to first line displayed on screen *)
|
||||||
|
val buffer = LineGap.goToLine (startLine, buffer)
|
||||||
|
|
||||||
|
(* get new startLine which may move screen depending on cursor movements *)
|
||||||
|
val startLine = TextWindow.getStartLine
|
||||||
|
(buffer, startLine, cursorIdx, windowWidth, windowHeight)
|
||||||
|
|
||||||
|
(* move buffer to new startLine as required by TextBuilder.build *)
|
||||||
|
val buffer = LineGap.goToLine (startLine, buffer)
|
||||||
|
|
||||||
|
val msgs = TextBuilder.build
|
||||||
|
( startLine
|
||||||
|
, cursorIdx
|
||||||
|
, buffer
|
||||||
|
, windowWidth
|
||||||
|
, windowHeight
|
||||||
|
, tempSearchList
|
||||||
|
, searchString
|
||||||
|
, initialMsg
|
||||||
|
)
|
||||||
|
|
||||||
|
val mode = NORMAL_MODE ""
|
||||||
|
in
|
||||||
|
NormalSearchModeWith.returnToNormalMode
|
||||||
|
( app
|
||||||
|
, buffer
|
||||||
|
, searchString
|
||||||
|
, tempSearchList
|
||||||
|
, startLine
|
||||||
|
, mode
|
||||||
|
, msgs
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
fun update (app, {searchString, tempSearchList}, msg, time) =
|
fun update (app, {searchString, tempSearchList}, msg, time) =
|
||||||
case msg of
|
case msg of
|
||||||
CHAR_EVENT chr => parseChr (app, searchString, chr)
|
CHAR_EVENT chr => addChr (app, searchString, chr)
|
||||||
| KEY_ESC => NormalFinish.clearMode app
|
| KEY_ESC => NormalFinish.clearMode app
|
||||||
| KEY_ENTER => finishSearch (app, searchString, tempSearchList)
|
| KEY_ENTER => finishSearch (app, searchString, tempSearchList)
|
||||||
| RESIZE_EVENT (width, height) => app
|
| RESIZE_EVENT (width, height) => app
|
||||||
|
|||||||
1
shf.mlb
1
shf.mlb
@@ -21,6 +21,7 @@ fcore/search-list.sml
|
|||||||
|
|
||||||
fcore/app-type.sml
|
fcore/app-type.sml
|
||||||
fcore/normal-mode/normal-mode-with.sml
|
fcore/normal-mode/normal-mode-with.sml
|
||||||
|
fcore/normal-mode/normal-search-mode-with.sml
|
||||||
fcore/app-with.sml
|
fcore/app-with.sml
|
||||||
|
|
||||||
fcore/text-constants.sml
|
fcore/text-constants.sml
|
||||||
|
|||||||
Reference in New Issue
Block a user