From 7a388f29834ed8ccb7d54dbfebe4767a0e9d71a7 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sat, 13 Sep 2025 18:23:55 +0100 Subject: [PATCH] add TextScroll function for centering line to cursor, and use it in 'NormalFinish.centreToCursor' function --- fcore/normal-mode/normal-finish.sml | 4 +--- fcore/text-scroll.sml | 9 ++++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/fcore/normal-mode/normal-finish.sml b/fcore/normal-mode/normal-finish.sml index cb089e6..b1a0262 100644 --- a/fcore/normal-mode/normal-finish.sml +++ b/fcore/normal-mode/normal-finish.sml @@ -128,7 +128,6 @@ struct ) end - (* todo: check; the way we get the startLine is almost certainly wrong *) fun centreToCursor (app: app_type) = let val @@ -146,8 +145,7 @@ struct val buffer = LineGap.goToIdx (cursorIdx, buffer) val cursorLine = LineGap.getLineNumberOfIdx (cursorIdx, buffer) - val startLine = - TextScroll.getStartLine (prevLineNumber, cursorLine, windowHeight div 2) + val startLine = TextScroll.getLineCentre (cursorLine, windowHeight) val buffer = LineGap.goToLine (startLine, buffer) val drawMsg = NormalModeTextBuilder.build diff --git a/fcore/text-scroll.sml b/fcore/text-scroll.sml index 6bc71c5..f8e9666 100644 --- a/fcore/text-scroll.sml +++ b/fcore/text-scroll.sml @@ -34,7 +34,6 @@ struct (* cursorLine > prevLineNumber *) let val howManyLinesWeCanFit = windowHeight div TC.ySpace - val howManyLinesWeCanFit = howManyLinesWeCanFit in if cursorLine > prevLineNumber + (howManyLinesWeCanFit - 3) then (* cursorLine is after the visible part of the screen @@ -43,4 +42,12 @@ struct else prevLineNumber end + + fun getLineCentre (cursorLine, windowHeight) = + let + val howManyLinesWeCanFit = windowHeight div TC.ySpace + val startLine = cursorLine - (howManyLinesWeCanFit div 2) + in + Int.max (startLine, 0) + end end