create text builder function to call for normal mode

This commit is contained in:
2025-09-12 12:05:57 +01:00
parent 67db4804fb
commit de57af242b
4 changed files with 156 additions and 90 deletions

View File

@@ -59,88 +59,6 @@ struct
end
end
(* gets line start idx, relative to right hd *)
fun helpGetLineStartIdx (startLine, curLine, rLnHd) =
if startLine > curLine then
let val lnPos = startLine - curLine - 1
in Vector.sub (rLnHd, lnPos) + 1
end
else
0
(* gets line start idx, absolute *)
fun helpGetLineAbsIdx (curIdx, startLine, curLine, rLnHd) =
let
val startIdx =
if startLine > curLine then
let val lnPos = startLine - curLine - 1
in Vector.sub (rLnHd, lnPos) + 1
end
else
0
in
curIdx + startIdx
end
fun getLineAbsIdx (startLine, lineGap: LineGap.t) =
let
val {rightLines, line = curLine, idx = curIdx, ...} = lineGap
in
case rightLines of
rLnHd :: _ => helpGetLineAbsIdx (curIdx, startLine, curLine, rLnHd)
| [] => (* should never happen *) 0
end
fun initEnv
( windowWidth
, windowHeight
, floatWindowWidth
, floatWindowHeight
, searchList
, searchLen
) =
if TC.textLineWidth > windowWidth then
{ w = windowWidth
, h = windowHeight
, startX = 5
, startY = 5
, z = 0.01
, fw = floatWindowWidth
, fh = floatWindowHeight
, r = 0.67
, g = 0.51
, b = 0.83
, hr = 0.211
, hg = 0.219
, hb = 0.25
, msgs = msgs
, searchList = searchList
, searchLen = searchLen
}
else
let
val startX = (windowWidth - TC.textLineWidth) div 2
val finishWidth = startX + TC.textLineWidth
in
{ w = finishWidth
, h = windowHeight
, startX = startX
, startY = 5
, z = 0.01
, fw = floatWindowWidth
, fh = floatWindowHeight
, r = 0.67
, g = 0.51
, b = 0.83
, hr = 0.211
, hg = 0.219
, hb = 0.25
, msgs = msgs
, searchList = searchList
, searchLen = searchLen
}
end
(* todo: add startX and startY parameters,
* so we can control where on the * screen the text starts from.
* Not worth doing until we have/in preparation of tiling functionality *)

View File

@@ -0,0 +1,115 @@
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
, searchString
, visualScrollColumn
, acc
) =
let
val {rightStrings, rightLines, line = curLine, idx = curIdx, ...} = buffer
in
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)
+ 1
(* get absolute idx of line *)
val absIdx = curIdx + strPos
val searchPos = BinSearch.equalOrMore (absIdx, searchList)
val env = Utils.initEnv
( windowWidth
, windowHeight
, floatWindowWidth
, floatWindowHeight
, searchList
, String.size searchString
, visualScrollColumn
, startLine
)
val {startX, startY, ...} = env
in
TextBuilderWithHighlight.build
( strPos
, shd
, stl
, lhd
, ltl
, startX
, startY
, 0
, startLine
, absIdx
, cursorPos
, env
, acc
, searchPos
)
end
| (_, _) => acc
end
fun buildWithExisting
( startLine
, cursorPos
, buffer: LineGap.t
, windowWidth
, windowHeight
, searchList: SearchList.t
, searchString
, visualScrollColumn
, acc
) =
startBuild
( startLine
, cursorPos
, buffer
, windowWidth
, windowHeight
, Real32.fromInt windowWidth
, Real32.fromInt windowHeight
, searchList
, searchString
, visualScrollColumn
, []
)
fun build
( startLine
, cursorPos
, buffer: LineGap.t
, windowWidth
, windowHeight
, searchList: SearchList.t
, searchString
, visualScrollColumn
) =
startBuild
( startLine
, cursorPos
, buffer
, windowWidth
, windowHeight
, Real32.fromInt windowWidth
, Real32.fromInt windowHeight
, searchList
, searchString
, visualScrollColumn
, []
)
end

View File

@@ -235,4 +235,40 @@ struct
fun advanceSearchPos (absIdx, searchPos, env) =
if isAfterSearchRange (absIdx, searchPos, env) then searchPos + 1
else searchPos
(* gets line start idx, relative to right hd *)
fun getRelativeLineStartFromRightHead (startLine, curLine, rLnHd) =
if startLine > curLine then
let val lnPos = startLine - curLine - 1
in Vector.sub (rLnHd, lnPos) + 1
end
else
0
(* gets line start idx, absolute *)
fun getAbsoluteLineStartFromRightHead (curIdx, startLine, curLine, rLnHd) =
let
val startIdx =
if startLine > curLine then
let val lnPos = startLine - curLine - 1
in Vector.sub (rLnHd, lnPos) + 1
end
else
0
in
curIdx + startIdx
end
fun getLineAbsIdxFromBuffer (startLine, buffer: LineGap.t) =
let
val {rightLines, line = curLine, idx = curIdx, ...} = buffer
in
case rightLines of
rLnHd :: _ =>
getAbsoluteLineStartFromRightHead (curIdx, startLine, curLine, rLnHd)
| [] =>
raise Fail
"text-builder-utils.sml 268:\
\should never call function when at end of buffer"
end
end

13
shf.mlb
View File

@@ -32,15 +32,12 @@ ann
in
fcore/rect.sml
fcore/pipe-cursor.sml
fcore/text-builder/text-builder-utils.sml
fcore/text-builder/text-builder-with-cursor.sml
fcore/text-builder/text-builder-with-highlight.sml
fcore/text-builder.sml
fcore/cursor-dfa/make-dfa-loop.sml
fcore/cursor-dfa/vi-word-dfa.sml
fcore/cursor-dfa/vi-caps-word-dfa.sml
fcore/cursor-dfa/vi-dlr-dfa.sml
end
fcore/text-builder/text-builder-utils.sml
fcore/text-builder/text-builder-with-cursor.sml
fcore/text-builder/text-builder-with-highlight.sml
fcore/text-builder/normal-mode-text-builder.sml
fcore/cursor.sml
fcore/text-window.sml
fcore/text-scroll.sml