@RequiresEdt
  private void update() {
    if (isDisposed) {
      return;
    }

    if (isBrokenMode) {
      documentOfPagesModel.removeAllPages(dataProvider.getProject());
      return;
    }

    long pagesAmountInFile;
    try {
      pagesAmountInFile = dataProvider.getPagesAmount();
    }
    catch (IOException e) {
      LOG.info(e);
      Messages.showErrorDialog(EditorBundle.message("large.file.editor.message.error.while.working.with.file.try.to.reopen.it"),
                               CommonBundle.getErrorTitle());
      return;
    }

    if (isNeedToShowCaret) {
      ensureTargetCaretPositionIsInFileBounds(pagesAmountInFile);
      targetVisiblePosition.set(targetCaretPosition.pageNumber,
                                targetVisiblePosition.verticalScrollOffset);  // we can't count the necessary offset at this stage
    }

    normalizePagesInDocumentListBeginning();

    if (pagesAmountInFile == 0) {
      return;
    }

    if (documentOfPagesModel.getPagesAmount() == 0) {
      long pageNumber = targetVisiblePosition.pageNumber == 0
                        ? 0
                        : targetVisiblePosition.pageNumber - 1;
      long prevPageNumber = pageNumber - 1;
      boolean isPrevPageNeeded = prevPageNumber >= 0;
      long nextPageNumber = pageNumber + 1;
      boolean isNextPageNeeded = nextPageNumber < pagesAmountInFile;

      int expectedNumberOfPages = 1 + (isPrevPageNeeded ? 1 : 0) + (isNextPageNeeded ? 1 : 0);
      List<Page> pagesFromCache = Stream.of(
        tryGetPageFromCache(prevPageNumber), tryGetPageFromCache(pageNumber), tryGetPageFromCache(nextPageNumber)
      ).toList();
      boolean allRequestedPagesAreCached = pagesFromCache.stream().filter(Objects::nonNull).count() == expectedNumberOfPages;

      if (allRequestedPagesAreCached) {
        pagesFromCache.stream().filter(Objects::nonNull).forEach(this::setNextPageIntoDocument);
      }
      else {
        if (isPrevPageNeeded && pagesFromCache.get(0) == null) requestReadPage(prevPageNumber);
        if (pagesFromCache.get(1) == null) requestReadPage(pageNumber);
        if (isNextPageNeeded && pagesFromCache.get(2) == null) requestReadPage(nextPageNumber);
        return;
      }
    }

    if (isNeedToTurnOnSoftWrapping()) {
      // TODO: 2019-05-21 need to notify user someway
      editor.getSettings().setUseSoftWraps(true);
    }

    normalizePagesInDocumentListEnding();

    ensureDocumentLastPageIsValid(pagesAmountInFile);

    if (wasViewPortInTheEndOfFileLastTime && isAllowedToFollowTheEndOfFile) {
      targetVisiblePosition.set(Long.MAX_VALUE, 0);
      isNeedToShowCaret = false;
      isAllowedToFollowTheEndOfFile = false;
    }

    tryReflectTargetCaretPositionToReal();

    tryReflectTargetSelectionToReal();

    tryNormalizeTargetVisiblePosition();

    if (!isLocalScrollBarStabilized) {
      tryScrollToTargetVisiblePosition();
    }

    updateGlobalStrollBarView();

    long nextPageNumberToAdd = tryGetNextPageNumberToAdd(pagesAmountInFile);
    if (nextPageNumberToAdd != -1) {
      Page nextPageToAdd = tryGetPageFromCache(nextPageNumberToAdd);
      if (nextPageToAdd != null) {
        setNextPageIntoDocument(nextPageToAdd);
        requestUpdate();
      }
      else {
        requestReadPage(nextPageNumberToAdd);
      }
      return;
    }

    pagesCache.clear();

    if (isNeedToShowCaret) {
      if (isLocalScrollBarStabilized) {
        showCaretThatIsNeededToShow();
      }
      else {
        requestUpdate();
        return;
      }
    }
    else {
      if (!isRealCaretMatchesTarget()) {
        setCaretToConvenientPosition();
      }
    }

    wasViewPortInTheEndOfFileLastTime = false;
    if (documentOfPagesModel.getLastPage().getPageNumber() == pagesAmountInFile - 1 &&
        myLocalInvisibleScrollBar.getValue() + myLocalInvisibleScrollBar.getHeight() == myLocalInvisibleScrollBar.getMaximum()) {
      wasViewPortInTheEndOfFileLastTime = true;
    }

    tryHighlightSearchResultsIfNeed();
  }
@RequiresEdt
  private void update()