extract a reusable function to calculate the scroll column in different contexts (can be used for a plain string or a LineGap.t; doesn't matter)
This commit is contained in:
@@ -2,10 +2,10 @@ structure TextScroll =
|
|||||||
struct
|
struct
|
||||||
structure TC = TextConstants
|
structure TC = TextConstants
|
||||||
|
|
||||||
(* Preqreuisite: move buffer to cursorIdx *)
|
(* calculates new scroll column from integer arguments *)
|
||||||
fun getScrollColumn (buffer, cursorIdx, windowWidth, prevScrollColumn) =
|
fun calculateScrollColumn
|
||||||
|
(startOfLine, cursorIdx, windowWidth, prevScrollColumn) =
|
||||||
let
|
let
|
||||||
val startOfLine = Cursor.vi0 (buffer, cursorIdx)
|
|
||||||
val newColumn = cursorIdx - startOfLine
|
val newColumn = cursorIdx - startOfLine
|
||||||
val howManyColumnsCanWeFit =
|
val howManyColumnsCanWeFit =
|
||||||
if windowWidth >= TC.textLineWidth then TC.textLineCount
|
if windowWidth >= TC.textLineWidth then TC.textLineCount
|
||||||
@@ -25,6 +25,15 @@ struct
|
|||||||
prevScrollColumn
|
prevScrollColumn
|
||||||
end
|
end
|
||||||
|
|
||||||
|
(* Preqreuisite: move buffer to cursorIdx *)
|
||||||
|
fun getScrollColumn (buffer, cursorIdx, windowWidth, prevScrollColumn) =
|
||||||
|
let
|
||||||
|
val startOfLine = Cursor.vi0 (buffer, cursorIdx)
|
||||||
|
in
|
||||||
|
calculateScrollColumn
|
||||||
|
(startOfLine, cursorIdx, windowWidth, prevScrollColumn)
|
||||||
|
end
|
||||||
|
|
||||||
fun getStartLine (prevLineNumber, cursorLine, windowHeight) =
|
fun getStartLine (prevLineNumber, cursorLine, windowHeight) =
|
||||||
if cursorLine <= (prevLineNumber + 3) then
|
if cursorLine <= (prevLineNumber + 3) then
|
||||||
(* cursorLine is prior to or same as prevLineNumber,
|
(* cursorLine is prior to or same as prevLineNumber,
|
||||||
|
|||||||
Reference in New Issue
Block a user