extract reusable function which can be used when a search string is changed, in NORMAL_SEARCH_MODE
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) =
|
||||
|
||||
@@ -1,22 +1,4 @@
|
||||
signature TEXT_BUILDER =
|
||||
sig
|
||||
(* Prerequisites: LineGap is moved to requested line first. *)
|
||||
val getLineAbsIdx: int * LineGap.t -> int
|
||||
|
||||
(* Prerequisites: LineGap is moved to requested line first. *)
|
||||
val build:
|
||||
int
|
||||
* int
|
||||
* LineGap.t
|
||||
* int
|
||||
* int
|
||||
* SearchList.t
|
||||
* string
|
||||
* MailboxType.t list
|
||||
-> MailboxType.t list
|
||||
end
|
||||
|
||||
structure TextBuilder :> TEXT_BUILDER =
|
||||
structure TextBuilder =
|
||||
struct
|
||||
open TextConstants
|
||||
structure TC = TextConstants
|
||||
@@ -361,7 +343,8 @@ struct
|
||||
end
|
||||
in
|
||||
(* builds a single text line from a string.
|
||||
* Used for getting Real32.real vector representing search input. *)
|
||||
* Used for getting Real32.real vector representing search input.
|
||||
* Todo: Add | cursor to show position of search-string-cursor. *)
|
||||
fun buildLineToList
|
||||
(str, startX, startY, endX, floatWindowWidth, floatWindowHeight) =
|
||||
loop
|
||||
|
||||
Reference in New Issue
Block a user