with cursor movements, instead of passing in functions as parameters (callbacks/higher order functions), functorise the cursor movement functions instead so we can take advantage of defunctorisation and avoid the runtime cost of closures/higher order functions/function pointers

This commit is contained in:
2025-01-09 22:30:51 +00:00
parent 7045b69ce8
commit deb24c2063
5 changed files with 152 additions and 111 deletions

37
fcore/finish.sml Normal file
View File

@@ -0,0 +1,37 @@
structure Finish =
struct
open AppType
fun buildTextAndClear (app: app_type, buffer, cursorIdx, searchList) =
let
val {windowWidth, windowHeight, startLine, searchString, ...} = app
(* move LineGap to first line displayed on screen
* and move searchList to line's start idx as well *)
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 lineIdx = TextBuilder.getLineAbsIdx (startLine, buffer)
val searchList = SearchList.goToNum (lineIdx, searchList)
val drawMsg = TextBuilder.build
( startLine
, cursorIdx
, buffer
, windowWidth
, windowHeight
, searchList
, searchString
)
val mode = NORMAL_MODE ""
in
AppWith.bufferAndCursorIdx
(app, buffer, cursorIdx, mode, startLine, searchList, drawMsg)
end
end