a bit of refactoring to allow addition of more tests

This commit is contained in:
2025-03-22 05:18:25 +00:00
parent deb24c2063
commit 649bcb66e1
9 changed files with 2912 additions and 2709 deletions

View File

@@ -108,10 +108,8 @@ struct
else else
let let
val searchList = val searchList =
if SearchList.exists (matchedIdx, searchList) then if SearchList.exists (matchedIdx, searchList) then searchList
searchList else SearchList.insert (matchedIdx, searchList)
else
SearchList.insert (matchedIdx, searchList)
in in
helpFromRange helpFromRange
( origIdx ( origIdx

File diff suppressed because it is too large Load Diff

View File

@@ -3,5 +3,5 @@ struct
val xSpace = 13 val xSpace = 13
val xSpace3 = xSpace * 3 val xSpace3 = xSpace * 3
val ySpace = 25 val ySpace = 25
val fontSize : Real32.real = 30.0 val fontSize: Real32.real = 30.0
end end

View File

@@ -8,10 +8,8 @@ struct
hd :: tl => hd :: tl =>
getStartLineBefore getStartLineBefore
(String.size hd - 1, hd, lineNum, absIdx, cursorIdx, tl) (String.size hd - 1, hd, lineNum, absIdx, cursorIdx, tl)
| [] => | [] => 0
0 else if absIdx = cursorIdx then
else
if absIdx = cursorIdx then
Int.max (lineNum - 1, 0) Int.max (lineNum - 1, 0)
else else
let let
@@ -26,63 +24,120 @@ struct
end end
fun getStartLineAfter fun getStartLineAfter
( sIdx, shd, lineNum, absIdx, cursorIdx, stl ( sIdx
, maxWidth, maxHeight, curWidth, curHeight , shd
, lineNum
, absIdx
, cursorIdx
, stl
, maxWidth
, maxHeight
, curWidth
, curHeight
, origLine , origLine
) = ) =
if sIdx = String.size shd then if sIdx = String.size shd then
case stl of case stl of
hd :: tl => hd :: tl =>
getStartLineAfter getStartLineAfter
( 0, hd, lineNum, absIdx, cursorIdx, tl ( 0
, maxWidth, maxHeight, curWidth, curHeight , hd
, lineNum
, absIdx
, cursorIdx
, tl
, maxWidth
, maxHeight
, curWidth
, curHeight
, origLine , origLine
) )
| [] => | [] => origLine
origLine else if absIdx = cursorIdx then
else
if absIdx = cursorIdx then
origLine origLine
else else
let let
val chr = String.sub (shd, sIdx) val chr = String.sub (shd, sIdx)
in in
if chr = #"\n" then if
chr = #"\n"
then
if curHeight + (ySpace * 3) >= maxHeight then if curHeight + (ySpace * 3) >= maxHeight then
getStartLineAfter getStartLineAfter
( sIdx + 1, shd, lineNum + 1, absIdx + 1, cursorIdx, stl ( sIdx + 1
, maxWidth, maxHeight, 0, curHeight + ySpace , shd
, lineNum + 1
, absIdx + 1
, cursorIdx
, stl
, maxWidth
, maxHeight
, 0
, curHeight + ySpace
, origLine + 1 , origLine + 1
) )
else else
getStartLineAfter getStartLineAfter
( sIdx + 1, shd, lineNum + 1, absIdx + 1, cursorIdx, stl ( sIdx + 1
, maxWidth, maxHeight, 0, curHeight + ySpace , shd
, lineNum + 1
, absIdx + 1
, cursorIdx
, stl
, maxWidth
, maxHeight
, 0
, curHeight + ySpace
, origLine , origLine
) )
else else if
if curWidth + xSpace <= maxWidth then curWidth + xSpace <= maxWidth
then
let let
val curWidth = curWidth + xSpace val curWidth = curWidth + xSpace
in in
getStartLineAfter getStartLineAfter
( sIdx + 1, shd, lineNum, absIdx + 1, cursorIdx, stl ( sIdx + 1
, maxWidth, maxHeight, curWidth, curHeight , shd
, lineNum
, absIdx + 1
, cursorIdx
, stl
, maxWidth
, maxHeight
, curWidth
, curHeight
, origLine , origLine
) )
end end
else else (* have to create visual line break *) if
(* have to create visual line break *) curHeight + (ySpace * 3) >= maxHeight
if curHeight + (ySpace * 3) >= maxHeight then then
getStartLineAfter getStartLineAfter
( sIdx + 1, shd, lineNum + 1, absIdx + 1, cursorIdx, stl ( sIdx + 1
, maxWidth, maxHeight, 0, curHeight + ySpace , shd
, lineNum + 1
, absIdx + 1
, cursorIdx
, stl
, maxWidth
, maxHeight
, 0
, curHeight + ySpace
, origLine + 1 , origLine + 1
) )
else else
getStartLineAfter getStartLineAfter
( sIdx + 1, shd, lineNum + 1, absIdx + 1, cursorIdx, stl ( sIdx + 1
, maxWidth, maxHeight, 0, curHeight + ySpace , shd
, lineNum + 1
, absIdx + 1
, cursorIdx
, stl
, maxWidth
, maxHeight
, 0
, curHeight + ySpace
, origLine , origLine
) )
end end
@@ -90,7 +145,14 @@ struct
(* Prerequisite: LineGap is moved to oldLine first. *) (* Prerequisite: LineGap is moved to oldLine first. *)
fun getStartLine (lineGap: LineGap.t, oldLine, cursorIdx, maxWidth, maxHeight) = fun getStartLine (lineGap: LineGap.t, oldLine, cursorIdx, maxWidth, maxHeight) =
let let
val {rightStrings, rightLines, line = curLine, idx = curIdx, leftStrings, ...} = lineGap val
{ rightStrings
, rightLines
, line = curLine
, idx = curIdx
, leftStrings
, ...
} = lineGap
in in
case (rightStrings, rightLines) of case (rightStrings, rightLines) of
(rStrHd :: rStrTl, rLnHd :: _) => (rStrHd :: rStrTl, rLnHd :: _) =>
@@ -115,20 +177,33 @@ struct
else if cursorIdx = absIdx + 1 then else if cursorIdx = absIdx + 1 then
(* double linebreak *) (* double linebreak *)
getStartLineBefore getStartLineBefore
(startIdx + 1, rStrHd, oldLine, absIdx + 1, cursorIdx, leftStrings) ( startIdx + 1
, rStrHd
, oldLine
, absIdx + 1
, cursorIdx
, leftStrings
)
else if cursorIdx > absIdx then else if cursorIdx > absIdx then
(* possibly move downwards *) (* possibly move downwards *)
getStartLineAfter getStartLineAfter
( startIdx, rStrHd, oldLine, absIdx, cursorIdx, rStrTl ( startIdx
, maxWidth, maxHeight, 0, 0 , rStrHd
, oldLine
, absIdx
, cursorIdx
, rStrTl
, maxWidth
, maxHeight
, 0
, 0
, oldLine , oldLine
) )
else else
(* keep current line *) (* keep current line *)
Int.max (oldLine - 1, 0) Int.max (oldLine - 1, 0)
end end
| (_, _) => | (_, _) => oldLine
oldLine
end end
fun helpCentreCursor (strPos, str, lineNum, stl, maxW, halfH, curW, curH) = fun helpCentreCursor (strPos, str, lineNum, stl, maxW, halfH, curW, curH) =
@@ -137,42 +212,37 @@ struct
hd :: tl => hd :: tl =>
helpCentreCursor helpCentreCursor
(String.size hd - 1, hd, lineNum, tl, maxW, halfH, curW, curH) (String.size hd - 1, hd, lineNum, tl, maxW, halfH, curW, curH)
| [] => | [] => (* return 0 for start of buffer *) 0
(* return 0 for start of buffer *)
0
else else
let let
val chr = String.sub (str, strPos) val chr = String.sub (str, strPos)
in in
if chr = #"\n" then if
chr = #"\n"
then
if curH + (ySpace * 3) >= halfH then if curH + (ySpace * 3) >= halfH then
(* if we exceeded half the screen *) (* if we exceeded half the screen *)
lineNum lineNum
else else
helpCentreCursor helpCentreCursor
( strPos - 1, str, lineNum - 1, stl, maxW, halfH (strPos - 1, str, lineNum - 1, stl, maxW, halfH, 0, curH + ySpace)
, 0, curH + ySpace else if
) curW + xSpace <= maxW
else then
if curW + xSpace <= maxW then
let let
val curW = curW + xSpace val curW = curW + xSpace
in in
helpCentreCursor helpCentreCursor
( strPos - 1, str, lineNum, stl, maxW, halfH (strPos - 1, str, lineNum, stl, maxW, halfH, curW + xSpace, curH)
, curW + xSpace, curH
)
end end
else else (* have to create visual line break *) if
(* have to create visual line break *) curH + (ySpace * 3) >= halfH
if curH + (ySpace * 3) >= halfH then then
(* if at limit, return current line lineNum *) (* if at limit, return current line lineNum *)
lineNum lineNum
else else
helpCentreCursor helpCentreCursor
( strPos - 1, str, lineNum - 1, stl, maxW, halfH (strPos - 1, str, lineNum - 1, stl, maxW, halfH, 0, curH + ySpace)
, 0, curH + ySpace
)
end end
(* search for prev \n, and once found, (* search for prev \n, and once found,
@@ -181,10 +251,8 @@ struct
if strPos < 0 then if strPos < 0 then
case stl of case stl of
hd :: tl => hd :: tl =>
getCursorStartLine getCursorStartLine (String.size hd - 1, hd, lineNum, tl, maxW, halfH)
(String.size hd - 1, hd, lineNum, tl, maxW, halfH) | [] => 0
| [] =>
0
else else
let let
val chr = String.sub (str, strPos) val chr = String.sub (str, strPos)
@@ -194,21 +262,15 @@ struct
helpCentreCursor helpCentreCursor
(strPos - 1, str, lineNum - 1, stl, maxW, halfH, xSpace, ySpace) (strPos - 1, str, lineNum - 1, stl, maxW, halfH, xSpace, ySpace)
else else
getCursorStartLine getCursorStartLine (strPos - 1, str, lineNum, stl, maxW, halfH)
(strPos - 1, str, lineNum, stl, maxW, halfH)
end end
fun getLineNum (strIdx, lhd, bufferLine) = fun getLineNum (strIdx, lhd, bufferLine) =
if Vector.length lhd = 0 then if Vector.length lhd = 0 then
bufferLine bufferLine
else if Vector.length lhd = 1 then else if Vector.length lhd = 1 then
let let val lineIdx = Vector.sub (lhd, 0)
val lineIdx = Vector.sub (lhd, 0) in if lineIdx < strIdx then bufferLine + 1 else bufferLine
in
if lineIdx < strIdx then
bufferLine + 1
else
bufferLine
end end
else else
let let
@@ -226,7 +288,14 @@ struct
fun getStartLineWithCursorCentered fun getStartLineWithCursorCentered
(lineGap: LineGap.t, cursorIdx, origLine, maxWidth, maxHeight) = (lineGap: LineGap.t, cursorIdx, origLine, maxWidth, maxHeight) =
let let
val {rightStrings, rightLines, idx = bufferIdx, line = bufferLine, leftStrings, ...} = lineGap val
{ rightStrings
, rightLines
, idx = bufferIdx
, line = bufferLine
, leftStrings
, ...
} = lineGap
in in
case (rightStrings, rightLines) of case (rightStrings, rightLines) of
(shd :: stl, lhd :: ltl) => (shd :: stl, lhd :: ltl) =>
@@ -255,11 +324,9 @@ struct
getCursorStartLine getCursorStartLine
(strIdx, stlhd, lineNum, leftStrings, maxWidth, maxHeight) (strIdx, stlhd, lineNum, leftStrings, maxWidth, maxHeight)
end end
| (_, _) => | (_, _) => origLine
origLine
end end
| (_, _) => | (_, _) => origLine
origLine
end end
fun helpIsCursorVisible fun helpIsCursorVisible
@@ -269,45 +336,66 @@ struct
hd :: tl => hd :: tl =>
helpIsCursorVisible helpIsCursorVisible
(0, hd, tl, absIdx, maxW, maxH, curW, curH, newCursorIdx) (0, hd, tl, absIdx, maxW, maxH, curW, curH, newCursorIdx)
| [] => | [] => true
true else if absIdx = newCursorIdx then
else
if absIdx = newCursorIdx then
true true
else else
let let
val chr = String.sub (str, strPos) val chr = String.sub (str, strPos)
in in
if chr = #"\n" then if
chr = #"\n"
then
if curH + (ySpace * 3) >= maxH then if curH + (ySpace * 3) >= maxH then
false false
else else
helpIsCursorVisible helpIsCursorVisible
( strPos + 1, str, stl, absIdx + 1 ( strPos + 1
, maxW, maxH, 0, curH + ySpace, newCursorIdx , str
, stl
, absIdx + 1
, maxW
, maxH
, 0
, curH + ySpace
, newCursorIdx
) )
else else if
if curW + xSpace <= maxW then curW + xSpace <= maxW
then
helpIsCursorVisible helpIsCursorVisible
( strPos + 1, str, stl, absIdx + 1 ( strPos + 1
, maxW, maxH, curW + xSpace, curH, newCursorIdx , str
, stl
, absIdx + 1
, maxW
, maxH
, curW + xSpace
, curH
, newCursorIdx
) )
else else (* have to create visual line break *) if
(* have to create visual line break *) curH + (ySpace * 3) >= maxH
if curH + (ySpace * 3) >= maxH then then
false false
else else
helpIsCursorVisible helpIsCursorVisible
( strPos + 1, str, stl, absIdx + 1 ( strPos + 1
, maxW, maxH, 0, curH + ySpace, newCursorIdx , str
, stl
, absIdx + 1
, maxW
, maxH
, 0
, curH + ySpace
, newCursorIdx
) )
end end
fun startIsCursorVisible fun startIsCursorVisible
(curIdx, shd, stl, lhd, startLine, curLine, maxW, maxH, newCursorIdx) = (curIdx, shd, stl, lhd, startLine, curLine, maxW, maxH, newCursorIdx) =
if startLine = curLine then if startLine = curLine then
helpIsCursorVisible helpIsCursorVisible (0, shd, stl, curIdx, maxW, maxH, 0, 0, newCursorIdx)
(0, shd, stl, curIdx, maxW, maxH, 0, 0, newCursorIdx)
else else
let let
val relativeLine = (curLine + Vector.length lhd) - startLine val relativeLine = (curLine + Vector.length lhd) - startLine
@@ -321,27 +409,40 @@ struct
(* Prerequisite: move LineGap.t to startLine *) (* Prerequisite: move LineGap.t to startLine *)
fun isCursorVisible (lineGap: LineGap.t, newCursorIdx, startLine, maxW, maxH) = fun isCursorVisible (lineGap: LineGap.t, newCursorIdx, startLine, maxW, maxH) =
let let
val {rightStrings, rightLines, line = curLine, idx = curIdx, ...} = lineGap val {rightStrings, rightLines, line = curLine, idx = curIdx, ...} =
lineGap
in in
case (rightStrings, rightLines) of case (rightStrings, rightLines) of
(shd :: stl, lhd :: ltl) => (shd :: stl, lhd :: ltl) =>
if startLine < curLine + Vector.length lhd then if startLine < curLine + Vector.length lhd then
(* startLine in this node *) (* startLine in this node *)
startIsCursorVisible startIsCursorVisible
( curIdx, shd, stl, lhd, startLine, curLine ( curIdx
, maxW, maxH, newCursorIdx , shd
, stl
, lhd
, startLine
, curLine
, maxW
, maxH
, newCursorIdx
) )
else else
(* startLine is in stl *) (* startLine is in stl *)
(case (stl, ltl) of (case (stl, ltl) of
(stlhd :: stltl, ltlhd :: ltltl) => (stlhd :: stltl, ltlhd :: ltltl) =>
startIsCursorVisible startIsCursorVisible
( curIdx, stlhd, stltl, ltlhd, startLine, curLine ( curIdx
, maxW, maxH, newCursorIdx , stlhd
, stltl
, ltlhd
, startLine
, curLine
, maxW
, maxH
, newCursorIdx
) )
| (_, _) => | (_, _) => true)
true) | (_, _) => true
| (_, _) =>
true
end end
end end

View File

@@ -1,15 +1,7 @@
signature INPUT_MSG = signature INPUT_MSG =
sig sig
datatype t = datatype t = CHAR_EVENT of char | KEY_ESC | RESIZE_EVENT of int * int
CHAR_EVENT of char
| KEY_ESC
| RESIZE_EVENT of int * int
end end
structure InputMsg :> INPUT_MSG = structure InputMsg :> INPUT_MSG =
struct struct datatype t = CHAR_EVENT of char | KEY_ESC | RESIZE_EVENT of int * int end
datatype t =
CHAR_EVENT of char
| KEY_ESC
| RESIZE_EVENT of int * int
end

View File

@@ -1,11 +1,7 @@
signature MAILBOX_TYPE = signature MAILBOX_TYPE =
sig sig
datatype t = datatype t = DRAW of DrawMsg.t
DRAW of DrawMsg.t
end end
structure MailboxType :> MAILBOX_TYPE = structure MailboxType :> MAILBOX_TYPE =
struct struct datatype t = DRAW of DrawMsg.t end
datatype t =
DRAW of DrawMsg.t
end

View File

@@ -29,7 +29,8 @@ fcore/text-window.sml
fcore/finish.sml fcore/finish.sml
fcore/move.sml fcore/move.sml
fcore/app-update.sml fcore/app-update.sml
(* TEST FILES *)
(* TEST FILES *)
test/Railroad/src/railroad.mlb test/Railroad/src/railroad.mlb
test/normal-move.sml
test/test.sml test/test.sml

1825
test/normal-move.sml Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff