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_SEARCH_MODE of
{ searchString: string
, tempSearchList: int vector
, tempSearchList: PersistentVector.t
, searchCursorIdx: int
, searchScrollColumn: int
}
@@ -13,7 +13,7 @@ struct
{ mode: mode
, buffer: LineGap.t
, bufferModifyTime: Time.time
, searchList: SearchList.t
, searchList: PersistentVector.t
, searchString: string
, windowWidth: int
, windowHeight: int

View File

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

View File

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

View File

@@ -39,8 +39,7 @@ struct
, fw: Real32.real
, fh: Real32.real
, searchList: int vector
, searchLen: int
, searchList: PersistentVector.t
}
fun initEnv
@@ -51,7 +50,6 @@ struct
, floatWindowWidth
, floatWindowHeight
, searchList
, searchLen
, visualScrollColumn
, startLine
) : env_data =
@@ -101,7 +99,6 @@ struct
, fh = floatWindowHeight
, searchList = searchList
, searchLen = searchLen
}
else
let
@@ -142,7 +139,6 @@ struct
, fh = floatWindowHeight
, searchList = searchList
, searchLen = searchLen
}
end
end
@@ -216,22 +212,6 @@ struct
, #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 *)
fun getRelativeLineStartFromRightHead (startLine, curLine, rLnHd) =
if startLine > curLine then

View File

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