From c95ae5eae389eb450c4a0bb46af77b279b00d8f0 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sun, 31 Aug 2025 07:40:31 +0100 Subject: [PATCH] add functionality to return from NORMAL_SEARCH_MODE back to NORMAL_MODE, saving new search string and new search list --- fcore/normal-mode/normal-search-mode-with.sml | 40 ++++++++++++++++ fcore/normal-mode/normal-search-mode.sml | 48 +++++++++++++++++-- shf.mlb | 1 + 3 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 fcore/normal-mode/normal-search-mode-with.sml diff --git a/fcore/normal-mode/normal-search-mode-with.sml b/fcore/normal-mode/normal-search-mode-with.sml new file mode 100644 index 0000000..62b5e94 --- /dev/null +++ b/fcore/normal-mode/normal-search-mode-with.sml @@ -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 diff --git a/fcore/normal-mode/normal-search-mode.sml b/fcore/normal-mode/normal-search-mode.sml index fa24c0b..bca782d 100644 --- a/fcore/normal-mode/normal-search-mode.sml +++ b/fcore/normal-mode/normal-search-mode.sml @@ -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 diff --git a/shf.mlb b/shf.mlb index 7bc160d..99c0633 100644 --- a/shf.mlb +++ b/shf.mlb @@ -21,6 +21,7 @@ fcore/search-list.sml fcore/app-type.sml fcore/normal-mode/normal-mode-with.sml +fcore/normal-mode/normal-search-mode-with.sml fcore/app-with.sml fcore/text-constants.sml