From dfb7ecb8679fd429ce12a33a4aaf0db22f20d198 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Thu, 11 Sep 2025 17:30:49 +0100 Subject: [PATCH] add new function to calculate the startLine --- fcore/normal-mode/normal-finish.sml | 1 - fcore/text-scroll.sml | 21 +++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/fcore/normal-mode/normal-finish.sml b/fcore/normal-mode/normal-finish.sml index 1dabf31..95dd165 100644 --- a/fcore/normal-mode/normal-finish.sml +++ b/fcore/normal-mode/normal-finish.sml @@ -17,7 +17,6 @@ struct (* calculate scroll column *) val buffer = LineGap.goToIdx (cursorIdx, buffer) val visualScrollColumn = TextScroll.getScrollColumn (buffer, cursorIdx, windowWidth) - val () = print (Int.toString visualScrollColumn ^ "\n") (* move LineGap to first line displayed on screen *) val buffer = LineGap.goToLine (startLine, buffer) diff --git a/fcore/text-scroll.sml b/fcore/text-scroll.sml index 0fea775..fb8dfef 100644 --- a/fcore/text-scroll.sml +++ b/fcore/text-scroll.sml @@ -17,8 +17,25 @@ struct else windowWidth div TC.xSpace in if columnDifference < howManyColumnsCanWeFit then 0 - else - columnDifference - howManyColumnsCanWeFit + else columnDifference - howManyColumnsCanWeFit end end + + 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 end