From b556fc7d6363fd1a276c650947a5873b0c7e6a3c Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sun, 14 Sep 2025 09:22:37 +0100 Subject: [PATCH] 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) --- fcore/text-scroll.sml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fcore/text-scroll.sml b/fcore/text-scroll.sml index f8e9666..351b2e8 100644 --- a/fcore/text-scroll.sml +++ b/fcore/text-scroll.sml @@ -2,10 +2,10 @@ structure TextScroll = struct structure TC = TextConstants - (* Preqreuisite: move buffer to cursorIdx *) - fun getScrollColumn (buffer, cursorIdx, windowWidth, prevScrollColumn) = + (* calculates new scroll column from integer arguments *) + fun calculateScrollColumn + (startOfLine, cursorIdx, windowWidth, prevScrollColumn) = let - val startOfLine = Cursor.vi0 (buffer, cursorIdx) val newColumn = cursorIdx - startOfLine val howManyColumnsCanWeFit = if windowWidth >= TC.textLineWidth then TC.textLineCount @@ -25,6 +25,15 @@ struct prevScrollColumn 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) = if cursorLine <= (prevLineNumber + 3) then (* cursorLine is prior to or same as prevLineNumber,