port over bug fixes from mutually recursive functions from test-builder-with-cursor.sml to text-builder-with-highlight.sml

This commit is contained in:
2025-09-13 03:02:13 +01:00
parent 916e94eaaa
commit a3b00e09d8
2 changed files with 125 additions and 12 deletions

View File

@@ -58,9 +58,9 @@ struct
else else
(* bin search lines *) (* bin search lines *)
let let
val searchPos = BinSearch.equalOrMore (pos + 1, line) val linePos = BinSearch.equalOrMore (pos + 1, line)
in in
if searchPos = ~1 then if linePos = ~1 then
(* next line is not in this node *) (* next line is not in this node *)
let let
val absIdx = absIdx - pos val absIdx = absIdx - pos
@@ -71,7 +71,7 @@ struct
end end
else else
let let
val lineOffset = Vector.sub (line, searchPos) val lineOffset = Vector.sub (line, linePos)
val newStrPos = lineOffset + 1 val newStrPos = lineOffset + 1
val absIdx = absIdx - pos + newStrPos val absIdx = absIdx - pos + newStrPos
val posY = posY + TC.ySpace val posY = posY + TC.ySpace

View File

@@ -15,13 +15,12 @@ struct
val posY = posY + TC.ySpace val posY = posY + TC.ySpace
val lineNumber = lineNumber + 1 val lineNumber = lineNumber + 1
in in
build skipToFirstVisibleColumn
( strPos ( strPos
, shd , shd
, stl , stl
, lhd , lhd
, ltl , ltl
, #startX env
, posY , posY
, 0 , 0
, lineNumber , lineNumber
@@ -47,7 +46,7 @@ struct
) )
| (_, _) => acc | (_, _) => acc
and skipToColumnStart and skipToNextLine
( pos ( pos
, str , str
, stl , stl
@@ -73,9 +72,9 @@ struct
else else
(* bin search lines *) (* bin search lines *)
let let
val searchPos = BinSearch.equalOrMore (pos + 1, #searchList env) val linePos = BinSearch.equalOrMore (pos + 1, line)
in in
if searchPos = ~1 then if linePos = ~1 then
(* next line is not in this node *) (* next line is not in this node *)
let let
val absIdx = absIdx - pos val absIdx = absIdx - pos
@@ -95,19 +94,18 @@ struct
end end
else else
let let
val lineOffset = Vector.sub (line, searchPos) val lineOffset = Vector.sub (line, linePos)
val newStrPos = lineOffset + 1 val newStrPos = lineOffset + 1
val absIdx = absIdx - pos + newStrPos val absIdx = absIdx - pos + newStrPos
val posY = posY + TC.ySpace val posY = posY + TC.ySpace
val lineNumber = lineNumber + 1 val lineNumber = lineNumber + 1
in in
build skipToFirstVisibleColumn
( newStrPos ( newStrPos
, str , str
, stl , stl
, line , line
, ltl , ltl
, #startX env
, posY , posY
, 0 , 0
, lineNumber , lineNumber
@@ -120,6 +118,105 @@ struct
end end
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
( pos
, str
, stl
, line
, ltl
, #startX env
, 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
, lineNumber
, absIdx + 1
, cursorIdx
, env
, acc
, searchPos
)
end
| chr =>
skipToFirstVisibleColumn
( pos + 1
, str
, stl
, line
, ltl
, posY
, column + 1
, lineNumber
, absIdx + 1
, cursorIdx
, env
, acc
, searchPos
)
and build and build
( pos ( pos
, str , str
@@ -174,7 +271,23 @@ struct
) )
| (_, _) => acc | (_, _) => acc
else if column < #scrollColumnStart env then else if column < #scrollColumnStart env then
skipToColumnStart skipToFirstVisibleColumn
( pos
, str
, stl
, line
, ltl
, posY
, column
, lineNumber
, absIdx
, cursorIdx
, env
, acc
, searchPos
)
else if column > #scrollColumnEnd env then
skipToNextLine
( pos ( pos
, str , str
, stl , stl