fix some type errors in the code

This commit is contained in:
2025-09-29 14:49:50 +01:00
parent 8ba16daf7a
commit d44799a794
5 changed files with 130 additions and 221 deletions

View File

@@ -4,7 +4,7 @@ struct
NORMAL_MODE of string NORMAL_MODE of string
| NORMAL_SEARCH_MODE of | NORMAL_SEARCH_MODE of
{ searchString: string { searchString: string
, tempSearchList: int vector , tempSearchList: PersistentVector.t
, searchCursorIdx: int , searchCursorIdx: int
, searchScrollColumn: int , searchScrollColumn: int
} }
@@ -13,7 +13,7 @@ struct
{ mode: mode { mode: mode
, buffer: LineGap.t , buffer: LineGap.t
, bufferModifyTime: Time.time , bufferModifyTime: Time.time
, searchList: SearchList.t , searchList: PersistentVector.t
, searchString: string , searchString: string
, windowWidth: int , windowWidth: int
, windowHeight: int , windowHeight: int

View File

@@ -11,6 +11,11 @@ struct
val maxSize = 32 val maxSize = 32
fun isEmpty t =
case t of
LEAF (_, sizes) = Vector.length sizes = 0
| _ => false
val empty = LEAF (#[], #[]) val empty = LEAF (#[], #[])
datatype append_result = APPEND of t | UPDATE of t datatype append_result = APPEND of t | UPDATE of t

View File

@@ -14,7 +14,6 @@ struct
, floatWindowWidth , floatWindowWidth
, floatWindowHeight , floatWindowHeight
, searchList , searchList
, searchString
, visualScrollColumn , visualScrollColumn
, acc , acc
) = ) =
@@ -36,7 +35,6 @@ struct
, floatWindowWidth , floatWindowWidth
, floatWindowHeight , floatWindowHeight
, searchList , searchList
, String.size searchString
, visualScrollColumn , visualScrollColumn
, startLine , startLine
) )
@@ -92,7 +90,6 @@ struct
, windowWidth , windowWidth
, windowHeight , windowHeight
, searchList: SearchList.t , searchList: SearchList.t
, searchString
, visualScrollColumn , visualScrollColumn
, acc , acc
) = ) =
@@ -105,7 +102,6 @@ struct
, Real32.fromInt windowWidth , Real32.fromInt windowWidth
, Real32.fromInt windowHeight , Real32.fromInt windowHeight
, searchList , searchList
, searchString
, visualScrollColumn , visualScrollColumn
, [] , []
) )
@@ -117,7 +113,6 @@ struct
, windowWidth , windowWidth
, windowHeight , windowHeight
, searchList: SearchList.t , searchList: SearchList.t
, searchString
, visualScrollColumn , visualScrollColumn
) = ) =
startBuild startBuild
@@ -129,7 +124,6 @@ struct
, Real32.fromInt windowWidth , Real32.fromInt windowWidth
, Real32.fromInt windowHeight , Real32.fromInt windowHeight
, searchList , searchList
, searchString
, visualScrollColumn , visualScrollColumn
, [] , []
) )

View File

@@ -39,8 +39,7 @@ struct
, fw: Real32.real , fw: Real32.real
, fh: Real32.real , fh: Real32.real
, searchList: int vector , searchList: PersistentVector.t
, searchLen: int
} }
fun initEnv fun initEnv
@@ -51,7 +50,6 @@ struct
, floatWindowWidth , floatWindowWidth
, floatWindowHeight , floatWindowHeight
, searchList , searchList
, searchLen
, visualScrollColumn , visualScrollColumn
, startLine , startLine
) : env_data = ) : env_data =
@@ -101,7 +99,6 @@ struct
, fh = floatWindowHeight , fh = floatWindowHeight
, searchList = searchList , searchList = searchList
, searchLen = searchLen
} }
else else
let let
@@ -142,7 +139,6 @@ struct
, fh = floatWindowHeight , fh = floatWindowHeight
, searchList = searchList , searchList = searchList
, searchLen = searchLen
} }
end end
end end
@@ -216,22 +212,6 @@ struct
, #highlightOnCharB env , #highlightOnCharB env
) )
fun isInSearchRange
(absIdx, searchPos, {searchList, searchLen, ...}: env_data) =
let val searchIdx = Vector.sub (searchList, searchPos)
in absIdx >= searchIdx andalso absIdx < searchIdx + searchLen
end
fun isAfterSearchRange
(absIdx, searchPos, {searchList, searchLen, ...}: env_data) =
let val searchIdx = Vector.sub (searchList, searchPos)
in absIdx >= searchIdx + searchLen
end
fun advanceSearchPos (absIdx, searchPos, env) =
if isAfterSearchRange (absIdx, searchPos, env) then searchPos + 1
else searchPos
(* gets line start idx, relative to right hd *) (* gets line start idx, relative to right hd *)
fun getRelativeLineStartFromRightHead (startLine, curLine, rLnHd) = fun getRelativeLineStartFromRightHead (startLine, curLine, rLnHd) =
if startLine > curLine then if startLine > curLine then

View File

@@ -9,7 +9,7 @@ struct
| _ => false | _ => false
fun goToFirstLineAfter fun goToFirstLineAfter
(stl, ltl, posY, lineNumber, absIdx, cursorIdx, env, acc, searchPos) = (stl, ltl, posY, lineNumber, absIdx, cursorIdx, env, acc) =
case (stl, ltl) of case (stl, ltl) of
(shd :: stl, lhd :: ltl) => (shd :: stl, lhd :: ltl) =>
if Vector.length lhd > 0 then if Vector.length lhd > 0 then
@@ -34,7 +34,6 @@ struct
, cursorIdx , cursorIdx
, env , env
, acc , acc
, searchPos
) )
end end
else else
@@ -48,24 +47,11 @@ struct
, cursorIdx , cursorIdx
, env , env
, acc , acc
, searchPos
) )
| (_, _) => acc | (_, _) => acc
and skipToNextLine and skipToNextLine
( pos (pos, str, stl, line, ltl, posY, lineNumber, absIdx, cursorIdx, env, acc) =
, str
, stl
, line
, ltl
, posY
, lineNumber
, absIdx
, cursorIdx
, env
, acc
, searchPos
) =
if Vector.length line = 0 then if Vector.length line = 0 then
let let
(* get index of buffer after this string *) (* get index of buffer after this string *)
@@ -73,7 +59,7 @@ struct
val absIdx = absIdx + String.size str val absIdx = absIdx + String.size str
in in
goToFirstLineAfter goToFirstLineAfter
(stl, ltl, posY, lineNumber, absIdx, cursorIdx, env, acc, searchPos) (stl, ltl, posY, lineNumber, absIdx, cursorIdx, env, acc)
end end
else else
(* bin search lines *) (* bin search lines *)
@@ -87,16 +73,7 @@ struct
val absIdx = absIdx + String.size str val absIdx = absIdx + String.size str
in in
goToFirstLineAfter goToFirstLineAfter
( stl (stl, ltl, posY, lineNumber, absIdx, cursorIdx, env, acc)
, ltl
, posY
, lineNumber
, absIdx
, cursorIdx
, env
, acc
, searchPos
)
end end
else else
let let
@@ -120,7 +97,6 @@ struct
, cursorIdx , cursorIdx
, env , env
, acc , acc
, searchPos
) )
end end
end end
@@ -139,26 +115,8 @@ struct
, cursorIdx , cursorIdx
, env: Utils.env_data , env: Utils.env_data
, acc , acc
, searchPos
) = ) =
if searchPos = Vector.length (#searchList env) then if pos = String.size str then
(* exhausted search list; call normal text-builder function *)
TextBuilderWithCursor.build
( pos
, str
, stl
, line
, ltl
, posX
, posY
, column
, lineNumber
, absIdx
, cursorIdx
, env
, acc
)
else if pos = String.size str then
case (stl, ltl) of case (stl, ltl) of
(str :: stl, line :: ltl) => (str :: stl, line :: ltl) =>
build build
@@ -175,154 +133,126 @@ struct
, cursorIdx , cursorIdx
, env , env
, acc , acc
, searchPos
) )
| (_, _) => acc | (_, _) => acc
else else
let case String.sub (str, pos) of
val searchPos = Utils.advanceSearchPos (absIdx, searchPos, env) #" " =>
in let
if searchPos = Vector.length (#searchList env) then val acc =
(* another check to see if we exhausted the searchList *) if absIdx = cursorIdx then
TextBuilderWithCursor.build Utils.makeCursor (posX, posY, env) :: acc
( pos else
, str
, stl
, line
, ltl
, posX
, posY
, column
, lineNumber
, absIdx
, cursorIdx
, env
, acc
)
else
case String.sub (str, pos) of
#" " =>
let
val acc =
if absIdx = cursorIdx then
Utils.makeCursor (posX, posY, env) :: acc
else
acc
val acc =
if Utils.isInSearchRange (absIdx, searchPos, env) then
Utils.makeHighlight (posX, posY, env) :: acc
else
acc
val posX =
if column < #scrollColumnStart env then #startX env
else posX + TC.xSpace
in
build
( pos + 1
, str
, stl
, line
, ltl
, posX
, posY
, column + 1
, lineNumber
, absIdx + 1
, cursorIdx
, env
, acc
, searchPos
)
end
| #"\n" =>
if lineNumber + 1 > #lastLineNumber env then
acc acc
val acc =
if PersistentVector.isInRange (absIdx, #searchList env) then
Utils.makeHighlight (posX, posY, env) :: acc
else else
let acc
val acc = val posX =
if absIdx = cursorIdx then if column < #scrollColumnStart env then #startX env
Utils.makeCursor (posX, posY, env) :: acc else posX + TC.xSpace
else in
acc build
in ( pos + 1
build , str
( pos + 1 , stl
, str , line
, stl , ltl
, line , posX
, ltl , posY
, #startX env , column + 1
, posY + TC.ySpace , lineNumber
, 0 , absIdx + 1
, lineNumber + 1 , cursorIdx
, absIdx + 1 , env
, cursorIdx , acc
, env )
, acc end
, searchPos | #"\n" =>
) if lineNumber + 1 > #lastLineNumber env then
end acc
| chr => else
if column < #scrollColumnStart env then let
build val acc =
( pos + 1 if absIdx = cursorIdx then
, str Utils.makeCursor (posX, posY, env) :: acc
, stl else
, line acc
, ltl in
, #startX env build
, posY ( pos + 1
, column + 1 , str
, lineNumber , stl
, absIdx + 1 , line
, cursorIdx , ltl
, env , #startX env
, acc , posY + TC.ySpace
, searchPos , 0
) , lineNumber + 1
else if column > #scrollColumnEnd env then , absIdx + 1
skipToNextLine , cursorIdx
( pos , env
, str , acc
, stl )
, line end
, ltl | chr =>
, posY if column < #scrollColumnStart env then
, lineNumber build
, absIdx ( pos + 1
, cursorIdx , str
, env , stl
, acc , line
, searchPos , ltl
) , #startX env
else , posY
let , column + 1
val acc = , lineNumber
if absIdx = cursorIdx then , absIdx + 1
Utils.makeCursorOnChr (chr, posX, posY, env) , cursorIdx
:: Utils.makeCursor (posX, posY, env) :: acc , env
else if Utils.isInSearchRange (absIdx, searchPos, env) then , acc
Utils.makeHighlightChr (chr, posX, posY, env) )
:: Utils.makeHighlight (posX, posY, env) :: acc else if column > #scrollColumnEnd env then
else skipToNextLine
Utils.makeChr (chr, posX, posY, env) :: acc ( pos
in , str
build , stl
( pos + 1 , line
, str , ltl
, stl , posY
, line , lineNumber
, ltl , absIdx
, posX + TC.xSpace , cursorIdx
, posY , env
, column + 1 , acc
, lineNumber )
, absIdx + 1 else
, cursorIdx let
, env val acc =
, acc if absIdx = cursorIdx then
, searchPos Utils.makeCursorOnChr (chr, posX, posY, env)
) :: Utils.makeCursor (posX, posY, env) :: acc
end else if PersistentVector.isInRange (absIdx, #searchList env) then
end Utils.makeHighlightChr (chr, posX, posY, env)
:: Utils.makeHighlight (posX, posY, env) :: acc
else
Utils.makeChr (chr, posX, posY, env) :: acc
in
build
( pos + 1
, str
, stl
, line
, ltl
, posX + TC.xSpace
, posY
, column + 1
, lineNumber
, absIdx + 1
, cursorIdx
, env
, acc
)
end
end end