EditorScrollController constructor

EditorScrollController({
  1. required EditorState editorState,
  2. bool shrinkWrap = false,
  3. ScrollController? scrollController,
})

Implementation

EditorScrollController({
  required this.editorState,
  this.shrinkWrap = false,
  ScrollController? scrollController,
}) {
  // if shrinkWrap is true, we will render the document with Column layout.
  // otherwise, we will render the document with ScrollablePositionedList.
  if (shrinkWrap) {
    void updateVisibleRange() {
      visibleRangeNotifier.value = (
        0,
        editorState.document.root.children.length - 1,
      );
    }

    updateVisibleRange();
    editorState.document.root.addListener(updateVisibleRange);

    shouldDisposeScrollController = scrollController == null;
    this.scrollController = scrollController ?? ScrollController();
    // listen to the scroll offset
    this.scrollController.addListener(
          () => offsetNotifier.value = this.scrollController.offset,
        );
  } else {
    // listen to the scroll offset
    _scrollOffsetSubscription = _scrollOffsetListener.changes.listen((value) {
      // the value from changes is the delta offset, so we add it to the current
      // offset to get the total offset.
      offsetNotifier.value = offsetNotifier.value + value;
    });

    _itemPositionsListener.itemPositions.addListener(_listenItemPositions);
  }
}