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:
2025-08-31 07:40:31 +01:00
parent a86befdea8
commit c95ae5eae3
3 changed files with 84 additions and 5 deletions

View 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

View File

@@ -2,9 +2,10 @@ structure NormalSearchMode =
struct
open AppType
open InputMsg
open MailboxType
(* todo: redraw based on results of tempSearchList *)
fun parseChr (app: app_type, searchString, chr) =
fun addChr (app: app_type, searchString, chr) =
let
val c = String.implode [chr]
val searchString = searchString ^ c
@@ -21,13 +22,50 @@ struct
NormalModeWith.mode (app, mode, [])
end
(* todo: switch to normal mode, save tempSearchList and searchString,
* and redraw *)
fun finishSearch (app: app_type, searchString, tempSearchList) = app
(* save search string and tempSearchList and return to normal mode *)
fun finishSearch (app: app_type, searchString, tempSearchList) =
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) =
case msg of
CHAR_EVENT chr => parseChr (app, searchString, chr)
CHAR_EVENT chr => addChr (app, searchString, chr)
| KEY_ESC => NormalFinish.clearMode app
| KEY_ENTER => finishSearch (app, searchString, tempSearchList)
| RESIZE_EVENT (width, height) => app