2025-09-11 16:17:56 +01:00
|
|
|
structure TextScroll =
|
|
|
|
|
struct
|
|
|
|
|
structure TC = TextConstants
|
|
|
|
|
|
|
|
|
|
(* Preqreuisite: move buffer to cursorIdx *)
|
|
|
|
|
fun getScrollColumn (buffer, cursorIdx, windowWidth) =
|
|
|
|
|
let
|
|
|
|
|
val startOfLine = Cursor.vi0 (buffer, cursorIdx)
|
|
|
|
|
val columnDifference = cursorIdx - startOfLine
|
|
|
|
|
in
|
|
|
|
|
if columnDifference = 0 then
|
|
|
|
|
0
|
|
|
|
|
else
|
|
|
|
|
let
|
|
|
|
|
val howManyColumnsCanWeFit =
|
|
|
|
|
if windowWidth >= TC.textLineWidth then TC.textLineCount
|
|
|
|
|
else windowWidth div TC.xSpace
|
2025-09-13 01:03:44 +01:00
|
|
|
val howManyColumnsCanWeFit = howManyColumnsCanWeFit - 1
|
2025-09-11 16:17:56 +01:00
|
|
|
in
|
2025-09-11 17:09:43 +01:00
|
|
|
if columnDifference < howManyColumnsCanWeFit then 0
|
2025-09-11 17:30:49 +01:00
|
|
|
else columnDifference - howManyColumnsCanWeFit
|
2025-09-11 16:17:56 +01:00
|
|
|
end
|
|
|
|
|
end
|
2025-09-11 17:30:49 +01:00
|
|
|
|
|
|
|
|
fun getStartLine (prevLineNumber, cursorLine, windowHeight) =
|
|
|
|
|
if cursorLine <= prevLineNumber then
|
|
|
|
|
(* if cursorLine is prior or same as prevLineNumber,
|
|
|
|
|
* then use cursorLine as scroll-line-start *)
|
|
|
|
|
cursorLine
|
|
|
|
|
else
|
|
|
|
|
(* cursorLine > prevLineNumber *)
|
|
|
|
|
let
|
|
|
|
|
val howManyLinesWeCanFit = windowHeight div TC.ySpace
|
|
|
|
|
in
|
|
|
|
|
if prevLineNumber + howManyLinesWeCanFit >= cursorLine then
|
|
|
|
|
prevLineNumber
|
|
|
|
|
else
|
|
|
|
|
let val lineDifference = cursorLine - prevLineNumber
|
|
|
|
|
in prevLineNumber + lineDifference
|
|
|
|
|
end
|
|
|
|
|
end
|
2025-09-11 16:17:56 +01:00
|
|
|
end
|