remove 'skipToFirstVisibleColumn' function in TextBuilder, as control flow is simpler if we have fewer mutually recursive functions and we can implement its functionality in the 'build' function instead. Also change the 'z' values for cursor and highlight; the cursor should appear above the highlight and now it does, but it previously didn't

This commit is contained in:
2025-09-13 23:22:40 +01:00
parent 7a388f2983
commit 2ab48626cd
3 changed files with 119 additions and 304 deletions

View File

@@ -75,8 +75,8 @@ struct
, cursorOnCharB = 0.83 , cursorOnCharB = 0.83
, charZ = 0.01 , charZ = 0.01
, cursorZ = 0.05 , cursorZ = 0.03
, highlightZ = 0.03 , highlightZ = 0.05
, startX = 5 , startX = 5
, startY = 5 , startY = 5
@@ -126,8 +126,8 @@ struct
, cursorOnCharB = 0.83 , cursorOnCharB = 0.83
, charZ = 0.01 , charZ = 0.01
, cursorZ = 0.05 , cursorZ = 0.03
, highlightZ = 0.03 , highlightZ = 0.05
, startX = startX , startX = startX
, startY = 5 , startY = 5

View File

@@ -15,12 +15,13 @@ struct
val posY = posY + TC.ySpace val posY = posY + TC.ySpace
val lineNumber = lineNumber + 1 val lineNumber = lineNumber + 1
in in
skipToFirstVisibleColumn build
( strPos ( strPos
, shd , shd
, stl , stl
, lhd , lhd
, ltl , ltl
, #startX env
, posY , posY
, 0 , 0
, lineNumber , lineNumber
@@ -77,116 +78,23 @@ struct
val posY = posY + TC.ySpace val posY = posY + TC.ySpace
val lineNumber = lineNumber + 1 val lineNumber = lineNumber + 1
in in
skipToFirstVisibleColumn
( newStrPos
, str
, stl
, line
, ltl
, posY
, 0
, lineNumber
, absIdx
, cursorIdx
, env
, acc
)
end
end
and skipToFirstVisibleColumn
( pos
, str
, stl
, line
, ltl
, posY
, column
, lineNumber
, absIdx
, cursorIdx
, env: Utils.env_data
, acc
) =
if column = #scrollColumnStart env then
(* return to build function *)
build build
( pos ( newStrPos
, str , str
, stl , stl
, line , line
, ltl , ltl
, #startX env , #startX env
, posY , posY
, column
, lineNumber
, absIdx
, cursorIdx
, env
, acc
)
else if pos = String.size str then
(* go to next node *)
case (stl, ltl) of
(shd :: stl, lhd :: ltl) =>
skipToFirstVisibleColumn
( 0
, shd
, stl
, lhd
, ltl
, posY
, column
, lineNumber
, absIdx
, cursorIdx
, env
, acc
)
| (_, _) => acc
else
case String.sub (str, pos) of
#"\n" =>
let
(* increment line lineNumber and posY,
* and then call skipToFirstVisibleColumn recursively.
* The recursive call check this condition:
* Is the new column 0 the same as the column the scroll starts at?
* If it is, then we call build, or else we continue skipping
* until we reach the start column. *)
val posY = posY + TC.ySpace
val lineNumber = lineNumber + 1
in
skipToFirstVisibleColumn
( pos + 1
, str
, stl
, line
, ltl
, posY
, 0 , 0
, lineNumber , lineNumber
, absIdx + 1 , absIdx
, cursorIdx , cursorIdx
, env , env
, acc , acc
) )
end end
| chr => end
skipToFirstVisibleColumn
( pos + 1
, str
, stl
, line
, ltl
, posY
, column + 1
, lineNumber
, absIdx + 1
, cursorIdx
, env
, acc
)
and build and build
( pos ( pos
@@ -222,62 +130,9 @@ struct
, acc , acc
) )
| (_, _) => acc | (_, _) => acc
else if column < #scrollColumnStart env then
skipToFirstVisibleColumn
( pos
, str
, stl
, line
, ltl
, posY
, column
, lineNumber
, absIdx
, cursorIdx
, env
, acc
)
else if column > #scrollColumnEnd env then
skipToNextLine
( pos
, str
, stl
, line
, ltl
, posY
, lineNumber
, absIdx
, cursorIdx
, env
, acc
)
else else
case String.sub (str, pos) of case String.sub (str, pos) of
#" " => #"\n" =>
let
val acc =
if absIdx = cursorIdx then
Utils.makeCursor (posX, posY, env) :: acc
else
acc
in
build
( pos + 1
, str
, stl
, line
, ltl
, posX + TC.xSpace
, posY
, column + 1
, lineNumber
, absIdx + 1
, cursorIdx
, env
, acc
)
end
| #"\n" =>
let let
val acc = val acc =
if absIdx = cursorIdx then if absIdx = cursorIdx then
@@ -306,7 +161,62 @@ struct
, acc , acc
) )
end end
| #" " =>
let
val acc =
if absIdx = cursorIdx then
Utils.makeCursor (posX, posY, env) :: acc
else
acc
in
build
( pos + 1
, str
, stl
, line
, ltl
, posX + TC.xSpace
, posY
, column + 1
, lineNumber
, absIdx + 1
, cursorIdx
, env
, acc
)
end
| chr => | chr =>
if column < #scrollColumnStart env then
build
( pos + 1
, str
, stl
, line
, ltl
, #startX env
, posY
, column + 1
, lineNumber
, absIdx + 1
, cursorIdx
, env
, acc
)
else if column > #scrollColumnEnd env then
skipToNextLine
( pos
, str
, stl
, line
, ltl
, posY
, lineNumber
, absIdx
, cursorIdx
, env
, acc
)
else
let let
val acc = val acc =
if absIdx = cursorIdx then if absIdx = cursorIdx then

View File

@@ -15,12 +15,13 @@ struct
val posY = posY + TC.ySpace val posY = posY + TC.ySpace
val lineNumber = lineNumber + 1 val lineNumber = lineNumber + 1
in in
skipToFirstVisibleColumn build
( strPos ( strPos
, shd , shd
, stl , stl
, lhd , lhd
, ltl , ltl
, #startX env
, posY , posY
, 0 , 0
, lineNumber , lineNumber
@@ -100,122 +101,24 @@ struct
val posY = posY + TC.ySpace val posY = posY + TC.ySpace
val lineNumber = lineNumber + 1 val lineNumber = lineNumber + 1
in in
skipToFirstVisibleColumn
( newStrPos
, str
, stl
, line
, ltl
, posY
, 0
, lineNumber
, absIdx
, cursorIdx
, env
, acc
, searchPos
)
end
end
and skipToFirstVisibleColumn
( pos
, str
, stl
, line
, ltl
, posY
, column
, lineNumber
, absIdx
, cursorIdx
, env: Utils.env_data
, acc
, searchPos
) =
if column = #scrollColumnStart env then
(* return to build function *)
build build
( pos ( newStrPos
, str , str
, stl , stl
, line , line
, ltl , ltl
, #startX env , #startX env
, posY , posY
, column
, lineNumber
, absIdx
, cursorIdx
, env
, acc
, searchPos
)
else if pos = String.size str then
(* go to next node *)
case (stl, ltl) of
(shd :: stl, lhd :: ltl) =>
skipToFirstVisibleColumn
( 0
, shd
, stl
, lhd
, ltl
, posY
, column
, lineNumber
, absIdx
, cursorIdx
, env
, acc
, searchPos
)
| (_, _) => acc
else
case String.sub (str, pos) of
#"\n" =>
let
(* increment line lineNumber and posY,
* and then call skipToFirstVisibleColumn recursively.
* The recursive call check this condition:
* Is the new column 0 the same as the column the scroll starts at?
* If it is, then we call build, or else we continue skipping
* until we reach the start column. *)
val posY = posY + TC.ySpace
val lineNumber = lineNumber + 1
in
skipToFirstVisibleColumn
( pos + 1
, str
, stl
, line
, ltl
, posY
, 0 , 0
, lineNumber , lineNumber
, absIdx + 1 , absIdx
, cursorIdx , cursorIdx
, env , env
, acc , acc
, searchPos , searchPos
) )
end end
| chr => end
skipToFirstVisibleColumn
( pos + 1
, str
, stl
, line
, ltl
, posY
, column + 1
, lineNumber
, absIdx + 1
, cursorIdx
, env
, acc
, searchPos
)
and build and build
( pos ( pos
@@ -270,37 +173,6 @@ struct
, searchPos , searchPos
) )
| (_, _) => acc | (_, _) => acc
else if column < #scrollColumnStart env then
skipToFirstVisibleColumn
( pos
, str
, stl
, line
, ltl
, posY
, column
, lineNumber
, absIdx
, cursorIdx
, env
, acc
, searchPos
)
else if column > #scrollColumnEnd env then
skipToNextLine
( pos
, str
, stl
, line
, ltl
, posY
, lineNumber
, absIdx
, cursorIdx
, env
, acc
, searchPos
)
else else
let let
val searchPos = Utils.advanceSearchPos (absIdx, searchPos, env) val searchPos = Utils.advanceSearchPos (absIdx, searchPos, env)
@@ -380,6 +252,39 @@ struct
) )
end end
| chr => | chr =>
if column < #scrollColumnStart env then
build
( pos + 1
, str
, stl
, line
, ltl
, #startX env
, posY
, column + 1
, lineNumber
, absIdx + 1
, cursorIdx
, env
, acc
, searchPos
)
else if column > #scrollColumnEnd env then
skipToNextLine
( pos
, str
, stl
, line
, ltl
, posY
, lineNumber
, absIdx
, cursorIdx
, env
, acc
, searchPos
)
else
let let
val acc = val acc =
if absIdx = cursorIdx then if absIdx = cursorIdx then