extract reusable function which can be used when a search string is changed, in NORMAL_SEARCH_MODE

This commit is contained in:
2025-09-01 02:18:23 +01:00
parent 9bae969511
commit 561e45c556
4 changed files with 88 additions and 39 deletions

View File

@@ -37,4 +37,33 @@ struct
, cursorIdx = cursorIdx
}
end
fun changeTempSearchString
(app: app_type, newBuffer, newStartLine, newMode, newMsgs) =
let
val
{ mode = _
, buffer = _
, searchString
, searchList
, startLine = _
, msgs = _
, bufferModifyTime
, windowWidth
, windowHeight
, cursorIdx
} = app
in
{ mode = newMode
, buffer = newBuffer
, startLine = newStartLine
, msgs = newMsgs
, searchString = searchString
, searchList = searchList
, bufferModifyTime = bufferModifyTime
, windowWidth = windowWidth
, windowHeight = windowHeight
, cursorIdx = cursorIdx
}
end
end

View File

@@ -4,26 +4,70 @@ struct
open InputMsg
open MailboxType
(* todo: redraw based on results of tempSearchList *)
fun addChr (app: app_type, searchString, chr) =
fun onSearchChanged (app: app_type, searchString, tempSearchList, buffer) =
let
val c = String.implode [chr]
val searchString = searchString ^ c
val {buffer, cursorIdx, ...} = app
val buffer = LineGap.goToIdx (cursorIdx - 1111, buffer)
val tempSearchList =
SearchList.buildRange (buffer, searchString, cursorIdx + 1111)
open DrawMsg
val {buffer, cursorIdx, startLine, windowWidth, windowHeight, ...} = app
val mode =
NORMAL_SEARCH_MODE
{searchString = searchString, tempSearchList = tempSearchList}
val floatWindowWidth = Real32.fromInt windowWidth
val floatWindowHeight = Real32.fromInt windowHeight
val searchStringPosY = windowHeight - TextConstants.ySpace - 5
val initialTextAcc = TextBuilder.buildLineToList
( searchString
, 5
, searchStringPosY
, windowWidth
, floatWindowWidth
, floatWindowHeight
)
val buffer = LineGap.goToLine (startLine, buffer)
val startLine = TextWindow.getStartLine
(buffer, startLine, cursorIdx, windowWidth, windowHeight)
val remainingWindowHeight = windowHeight - (TextConstants.ySpace * 2)
val msgs = TextBuilder.buildWithExisting
( startLine
, cursorIdx
, buffer
, windowWidth
, remainingWindowHeight
, floatWindowWidth
, floatWindowHeight
, tempSearchList
, searchString
, []
, initialTextAcc
, []
)
in
NormalModeWith.mode (app, mode, [])
NormalSearchModeWith.changeTempSearchString
(app, buffer, startLine, mode, msgs)
end
fun addChr (app: app_type, searchString, chr) =
let
val {cursorIdx, buffer, ...} = app
val c = String.implode [chr]
val searchString = searchString ^ c
val buffer = LineGap.goToIdx (cursorIdx - 1111, buffer)
val tempSearchList =
SearchList.buildRange (buffer, searchString, cursorIdx + 1111)
in
onSearchChanged (app, searchString, tempSearchList, buffer)
end
(* save search string and tempSearchList and return to normal mode *)
fun finishSearch (app: app_type, searchString, tempSearchList) =
fun finishSearch (app: app_type, searchString, tempSearchList) =
let
val {buffer, cursorIdx, windowWidth, windowHeight, startLine, ...} = app
val buffer = LineGap.goToStart buffer
@@ -53,14 +97,7 @@ struct
val mode = NORMAL_MODE ""
in
NormalSearchModeWith.returnToNormalMode
( app
, buffer
, searchString
, tempSearchList
, startLine
, mode
, msgs
)
(app, buffer, searchString, tempSearchList, startLine, mode, msgs)
end
fun update (app, {searchString, tempSearchList}, msg, time) =