adjustScroll method

void adjustScroll(
  1. int viewportHeight
)

Adjusts the scroll offset based on the viewport height.

Implementation

void adjustScroll(int viewportHeight) {
  final lines = controller.value.lines;
  if (lines.isEmpty || viewportHeight <= 0) return;
  final currentCursorLine = cursorLine.clamp(0, lines.length - 1);
  if (currentCursorLine < scrollOffset) {
    scrollOffset = currentCursorLine;
  } else if (currentCursorLine >= scrollOffset + viewportHeight) {
    scrollOffset = currentCursorLine - viewportHeight + 1;
  }
}