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,30 +133,8 @@ struct
, cursorIdx , cursorIdx
, env , env
, acc , acc
, searchPos
) )
| (_, _) => acc | (_, _) => acc
else
let
val searchPos = Utils.advanceSearchPos (absIdx, searchPos, env)
in
if searchPos = Vector.length (#searchList env) then
(* another check to see if we exhausted the searchList *)
TextBuilderWithCursor.build
( pos
, str
, stl
, line
, ltl
, posX
, posY
, column
, lineNumber
, absIdx
, cursorIdx
, env
, acc
)
else else
case String.sub (str, pos) of case String.sub (str, pos) of
#" " => #" " =>
@@ -209,7 +145,7 @@ struct
else else
acc acc
val acc = val acc =
if Utils.isInSearchRange (absIdx, searchPos, env) then if PersistentVector.isInRange (absIdx, #searchList env) then
Utils.makeHighlight (posX, posY, env) :: acc Utils.makeHighlight (posX, posY, env) :: acc
else else
acc acc
@@ -231,7 +167,6 @@ struct
, cursorIdx , cursorIdx
, env , env
, acc , acc
, searchPos
) )
end end
| #"\n" => | #"\n" =>
@@ -259,7 +194,6 @@ struct
, cursorIdx , cursorIdx
, env , env
, acc , acc
, searchPos
) )
end end
| chr => | chr =>
@@ -278,7 +212,6 @@ struct
, cursorIdx , cursorIdx
, env , env
, acc , acc
, searchPos
) )
else if column > #scrollColumnEnd env then else if column > #scrollColumnEnd env then
skipToNextLine skipToNextLine
@@ -293,7 +226,6 @@ struct
, cursorIdx , cursorIdx
, env , env
, acc , acc
, searchPos
) )
else else
let let
@@ -301,7 +233,7 @@ struct
if absIdx = cursorIdx then if absIdx = cursorIdx then
Utils.makeCursorOnChr (chr, posX, posY, env) Utils.makeCursorOnChr (chr, posX, posY, env)
:: Utils.makeCursor (posX, posY, env) :: acc :: Utils.makeCursor (posX, posY, env) :: acc
else if Utils.isInSearchRange (absIdx, searchPos, env) then else if PersistentVector.isInRange (absIdx, #searchList env) then
Utils.makeHighlightChr (chr, posX, posY, env) Utils.makeHighlightChr (chr, posX, posY, env)
:: Utils.makeHighlight (posX, posY, env) :: acc :: Utils.makeHighlight (posX, posY, env) :: acc
else else
@@ -321,8 +253,6 @@ struct
, cursorIdx , cursorIdx
, env , env
, acc , acc
, searchPos
) )
end end
end
end end