Editor::VerticalCentreCaret() in Editor.cxx computes newTop by
centering the caret, but only clamps its lower bound.
Other scrolling paths clamp their target line with
std::clamp<sci::line>(..., 0, MaxScrollPos()). This function does not,
and SetTopLine() also accepts a value above MaxScrollPos().</sci::line>
Fix: clamp newTop like the neighbouring scrolling code:
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -1021,11 +1021,11 @@ void Editor::VerticalCentreCaret() {
void Editor::VerticalCentreCaret() {
const Sci::Line lineDoc =
pdoc->SciLineFromPosition(sel.IsRectangular() ? sel.Rectangular().caret.Position() : sel.MainCaret());
const Sci::Line lineDisplay = pcs->DisplayFromDoc(lineDoc);
- const Sci::Line newTop = lineDisplay - (LinesOnScreen() / 2);
+ const Sci::Line newTop = std::clamp<Sci::Line>(lineDisplay - (LinesOnScreen() / 2), 0, MaxScrollPos());
if (topLine != newTop) {
- SetTopLine(newTop > 0 ? newTop : 0);
+ SetTopLine(newTop);
SetVerticalScrollPos();
RedrawRect(GetClientRectangle());
}
}
Committed with [fce5e5].
Related
Commit: [fce5e5]