extract reusable function which can be used when a search string is changed, in NORMAL_SEARCH_MODE
This commit is contained in:
BIN
.temp.txt.swp
Normal file
BIN
.temp.txt.swp
Normal file
Binary file not shown.
@@ -37,4 +37,33 @@ struct
|
|||||||
, cursorIdx = cursorIdx
|
, cursorIdx = cursorIdx
|
||||||
}
|
}
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -4,22 +4,66 @@ struct
|
|||||||
open InputMsg
|
open InputMsg
|
||||||
open MailboxType
|
open MailboxType
|
||||||
|
|
||||||
(* todo: redraw based on results of tempSearchList *)
|
fun onSearchChanged (app: app_type, searchString, tempSearchList, buffer) =
|
||||||
fun addChr (app: app_type, searchString, chr) =
|
|
||||||
let
|
let
|
||||||
val c = String.implode [chr]
|
open DrawMsg
|
||||||
val searchString = searchString ^ c
|
|
||||||
|
|
||||||
val {buffer, cursorIdx, ...} = app
|
|
||||||
val buffer = LineGap.goToIdx (cursorIdx - 1111, buffer)
|
|
||||||
val tempSearchList =
|
|
||||||
SearchList.buildRange (buffer, searchString, cursorIdx + 1111)
|
|
||||||
|
|
||||||
|
val {buffer, cursorIdx, startLine, windowWidth, windowHeight, ...} = app
|
||||||
val mode =
|
val mode =
|
||||||
NORMAL_SEARCH_MODE
|
NORMAL_SEARCH_MODE
|
||||||
{searchString = searchString, tempSearchList = tempSearchList}
|
{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
|
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
|
end
|
||||||
|
|
||||||
(* save search string and tempSearchList and return to normal mode *)
|
(* save search string and tempSearchList and return to normal mode *)
|
||||||
@@ -53,14 +97,7 @@ struct
|
|||||||
val mode = NORMAL_MODE ""
|
val mode = NORMAL_MODE ""
|
||||||
in
|
in
|
||||||
NormalSearchModeWith.returnToNormalMode
|
NormalSearchModeWith.returnToNormalMode
|
||||||
( app
|
(app, buffer, searchString, tempSearchList, startLine, mode, msgs)
|
||||||
, buffer
|
|
||||||
, searchString
|
|
||||||
, tempSearchList
|
|
||||||
, startLine
|
|
||||||
, mode
|
|
||||||
, msgs
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
fun update (app, {searchString, tempSearchList}, msg, time) =
|
fun update (app, {searchString, tempSearchList}, msg, time) =
|
||||||
|
|||||||
@@ -1,22 +1,4 @@
|
|||||||
signature TEXT_BUILDER =
|
structure TextBuilder =
|
||||||
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 =
|
|
||||||
struct
|
struct
|
||||||
open TextConstants
|
open TextConstants
|
||||||
structure TC = TextConstants
|
structure TC = TextConstants
|
||||||
@@ -361,7 +343,8 @@ struct
|
|||||||
end
|
end
|
||||||
in
|
in
|
||||||
(* builds a single text line from a string.
|
(* 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
|
fun buildLineToList
|
||||||
(str, startX, startY, endX, floatWindowWidth, floatWindowHeight) =
|
(str, startX, startY, endX, floatWindowWidth, floatWindowHeight) =
|
||||||
loop
|
loop
|
||||||
|
|||||||
Reference in New Issue
Block a user