Add 'shf/' from commit 'b6c5a95b664aeb861d7b33ffc9eefe447ba99dd7'
git-subtree-dir: shf git-subtree-mainline:401408448fgit-subtree-split:b6c5a95b66
This commit is contained in:
142
shf/fcore/text-builder/normal-mode-text-builder.sml
Normal file
142
shf/fcore/text-builder/normal-mode-text-builder.sml
Normal file
@@ -0,0 +1,142 @@
|
||||
structure NormalModeTextBuilder =
|
||||
struct
|
||||
structure Utils = TextBuilderUtils
|
||||
|
||||
(* Prerequisite to all functions in this structure:
|
||||
* - Move buffer to startLine before calling any function. *)
|
||||
|
||||
fun startBuild
|
||||
( startLine
|
||||
, cursorPos
|
||||
, buffer: LineGap.t
|
||||
, windowWidth
|
||||
, windowHeight
|
||||
, floatWindowWidth
|
||||
, floatWindowHeight
|
||||
, searchList
|
||||
, visualScrollColumn
|
||||
, acc
|
||||
) =
|
||||
let
|
||||
val
|
||||
{ rightStrings
|
||||
, rightLines
|
||||
, line = curLine
|
||||
, idx = curIdx
|
||||
, textLength
|
||||
, ...
|
||||
} = buffer
|
||||
|
||||
val env = Utils.initEnv
|
||||
( 0
|
||||
, 0
|
||||
, windowWidth
|
||||
, windowHeight
|
||||
, floatWindowWidth
|
||||
, floatWindowHeight
|
||||
, searchList
|
||||
, visualScrollColumn
|
||||
, startLine
|
||||
)
|
||||
val {startX, startY, ...} = env
|
||||
in
|
||||
if textLength = 1 then
|
||||
(* empty string, so there is nothing we can draw
|
||||
* except a cursor at the line start.
|
||||
* An empty string is usually thought of to have a length of 0
|
||||
* and this is true, but we always have a \n at the end of the buffer
|
||||
* to respect Unix-style file endings, which we always uphold.
|
||||
* So, for us, an empty string has a length of 1. *)
|
||||
[Utils.makeCursor (startX, startY, env)]
|
||||
else
|
||||
case (rightStrings, rightLines) of
|
||||
(shd :: stl, lhd :: ltl) =>
|
||||
let
|
||||
(* get relative index of line to start building from *)
|
||||
val strPos =
|
||||
Utils.getRelativeLineStartFromRightHead
|
||||
(startLine, curLine, lhd)
|
||||
(* get absolute idx of line *)
|
||||
val absIdx = curIdx + strPos
|
||||
in
|
||||
if PersistentVector.isEmpty searchList then
|
||||
TextBuilderWithCursor.build
|
||||
( strPos
|
||||
, shd
|
||||
, stl
|
||||
, lhd
|
||||
, ltl
|
||||
, startX
|
||||
, startY
|
||||
, 0
|
||||
, startLine
|
||||
, absIdx
|
||||
, cursorPos
|
||||
, env
|
||||
, acc
|
||||
)
|
||||
else
|
||||
TextBuilderWithHighlight.build
|
||||
( strPos
|
||||
, shd
|
||||
, stl
|
||||
, lhd
|
||||
, ltl
|
||||
, startX
|
||||
, startY
|
||||
, 0
|
||||
, startLine
|
||||
, absIdx
|
||||
, cursorPos
|
||||
, env
|
||||
, acc
|
||||
)
|
||||
end
|
||||
| (_, _) => acc
|
||||
end
|
||||
|
||||
fun buildWithExisting
|
||||
( startLine
|
||||
, cursorPos
|
||||
, buffer: LineGap.t
|
||||
, windowWidth
|
||||
, windowHeight
|
||||
, searchList
|
||||
, visualScrollColumn
|
||||
, acc
|
||||
) =
|
||||
startBuild
|
||||
( startLine
|
||||
, cursorPos
|
||||
, buffer
|
||||
, windowWidth
|
||||
, windowHeight
|
||||
, Real32.fromInt windowWidth
|
||||
, Real32.fromInt windowHeight
|
||||
, searchList
|
||||
, visualScrollColumn
|
||||
, []
|
||||
)
|
||||
|
||||
fun build
|
||||
( startLine
|
||||
, cursorPos
|
||||
, buffer: LineGap.t
|
||||
, windowWidth
|
||||
, windowHeight
|
||||
, searchList
|
||||
, visualScrollColumn
|
||||
) =
|
||||
startBuild
|
||||
( startLine
|
||||
, cursorPos
|
||||
, buffer
|
||||
, windowWidth
|
||||
, windowHeight
|
||||
, Real32.fromInt windowWidth
|
||||
, Real32.fromInt windowHeight
|
||||
, searchList
|
||||
, visualScrollColumn
|
||||
, []
|
||||
)
|
||||
end
|
||||
Reference in New Issue
Block a user