fill in todo where strIdx is in tl, in text-window.sml function 'getStartLineWithCursorCentered

This commit is contained in:
2024-10-30 11:12:12 +00:00
parent 601a341992
commit 1316cdfe13
2 changed files with 40 additions and 26 deletions

View File

@@ -196,7 +196,7 @@ struct
case stl of case stl of
hd :: tl => hd :: tl =>
getCursorStartLine getCursorStartLine
(String.size hd - 1, str, lineNum, tl, maxW, halfH) (String.size hd - 1, hd, lineNum, tl, maxW, halfH)
| [] => | [] =>
0 0
else else
@@ -212,22 +212,7 @@ struct
(strPos - 1, str, lineNum, stl, maxW, halfH) (strPos - 1, str, lineNum, stl, maxW, halfH)
end end
(* Prerequisite: LineGap is moved to cursor *) fun getLineNum (strIdx, lhd, bufferLine) =
fun getStartLineWithCursorCentered
(lineGap: LineGap.t, cursorIdx, origLine, maxWidth, maxHeight) =
let
val {rightStrings, rightLines, idx = bufferIdx, line = bufferLine, leftStrings, ...} = lineGap
in
case (rightStrings, rightLines) of
(shd :: stl, lhd :: ltl) =>
let
(* convert absolute cursorIdx to idx relative to hd string *)
val strIdx = cursorIdx - bufferIdx
in
if strIdx < String.size shd then
(* strIdx is in hd *)
let
val lineNum =
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
@@ -250,13 +235,42 @@ struct
else else
bufferLine + 1 bufferLine + 1
end end
(* Prerequisite: LineGap is moved to cursor *)
fun getStartLineWithCursorCentered
(lineGap: LineGap.t, cursorIdx, origLine, maxWidth, maxHeight) =
let
val {rightStrings, rightLines, idx = bufferIdx, line = bufferLine, leftStrings, ...} = lineGap
in
case (rightStrings, rightLines) of
(shd :: stl, lhd :: ltl) =>
let
(* convert absolute cursorIdx to idx relative to hd string *)
val strIdx = cursorIdx - bufferIdx
in
if strIdx < String.size shd then
(* strIdx is in hd *)
let
val lineNum = getLineNum (strIdx, lhd, bufferLine)
in in
getCursorStartLine getCursorStartLine
(strIdx, shd, lineNum, leftStrings, maxWidth, maxHeight) (strIdx, shd, lineNum, leftStrings, maxWidth, maxHeight)
end end
else else
(* todo: strIdx is in tl *) (* strIdx is in tl *)
raise Match case (stl, ltl) of
(stlhd :: stltl, ltlhd :: _) =>
let
val strIdx = strIdx - String.size shd
val bufferLine = bufferLine + Vector.length lhd
val lineNum = getLineNum (strIdx, ltlhd, bufferLine)
val leftStrings = shd :: leftStrings
in
getCursorStartLine
(strIdx, stlhd, lineNum, leftStrings, maxWidth, maxHeight)
end
| (_, _) =>
origLine
end end
| (_, _) => | (_, _) =>
origLine origLine

BIN
shf

Binary file not shown.