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