isPositionVisibleGlobally static method

bool isPositionVisibleGlobally(
  1. DocumentPosition position,
  2. Size globalSize, [
  3. Finder? finder
])

Returns true if the entire content rectangle at position is visible on screen, or false otherwise.

By default, this method expects a single SuperEditor in the widget tree and finds it byType. To specify one SuperEditor among many, pass a superEditorFinder.

Implementation

static bool isPositionVisibleGlobally(DocumentPosition position, Size globalSize, [Finder? finder]) {
  final documentLayout = findDocumentLayout(finder);
  final positionRect = documentLayout.getRectForPosition(position)!;
  final globalDocumentOffset = documentLayout.getGlobalOffsetFromDocumentOffset(Offset.zero);
  final globalPositionRect = positionRect.translate(globalDocumentOffset.dx, globalDocumentOffset.dy);

  return globalPositionRect.top >= 0 &&
      globalPositionRect.left >= 0 &&
      globalPositionRect.bottom <= globalSize.height &&
      globalPositionRect.right <= globalSize.width;
}