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
|
|
|
|
|
in
|
2025-09-11 17:09:43 +01:00
|
|
|
if columnDifference < howManyColumnsCanWeFit then 0
|
|
|
|
|
else
|
|
|
|
|
columnDifference - howManyColumnsCanWeFit
|
2025-09-11 16:17:56 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|