scrollOnPageUpKeyPress function

ExecutionInstruction scrollOnPageUpKeyPress({
  1. required SuperEditorContext editContext,
  2. required KeyEvent keyEvent,
})

Scrolls up by the viewport height, or as high as possible, when the user presses the Page Up key.

Implementation

ExecutionInstruction scrollOnPageUpKeyPress({
  required SuperEditorContext editContext,
  required KeyEvent keyEvent,
}) {
  if (keyEvent is! KeyDownEvent && keyEvent is! KeyRepeatEvent) {
    return ExecutionInstruction.continueExecution;
  }

  if (keyEvent.logicalKey.keyId != LogicalKeyboardKey.pageUp.keyId) {
    return ExecutionInstruction.continueExecution;
  }

  final scroller = editContext.scroller;

  scroller.animateTo(
    max(scroller.scrollOffset - scroller.viewportDimension, scroller.minScrollExtent),
    duration: const Duration(milliseconds: 150),
    curve: Curves.decelerate,
  );

  return ExecutionInstruction.haltExecution;
}