public void updateSelection(boolean removePreviousSelection, boolean removeAllPreviousSelections, boolean adjustScrollPosition) {
    Editor editor = mySearchResults.getEditor();
    if (removeAllPreviousSelections) {
      editor.getCaretModel().removeSecondaryCarets();
    }
    FindModel findModel = mySearchResults.getFindModel();
    FindResult cursor = mySearchResults.getCursor();
    if (cursor == null) {
      if (removePreviousSelection && !myHadSelectionInitially && findModel.isGlobal()) {
        editor.getSelectionModel().removeSelection();
      }
      return;
    }
    if (findModel.isGlobal()) {
      if (removePreviousSelection || removeAllPreviousSelections) {
        FoldingModel foldingModel = editor.getFoldingModel();
        FoldRegion[] allRegions = editor.getFoldingModel().getAllFoldRegions();

        foldingModel.runBatchFoldingOperation(() -> {
          for (FoldRegion region : myRegionsToRestore) {
            if (region.isValid()) {
              region.setExpanded(false);
            }
          }
          myRegionsToRestore.clear();
          for (FoldRegion region : allRegions) {
            if (region.isValid() && cursor.intersects(region) && !region.isExpanded()) {
              region.setExpanded(true);
              myRegionsToRestore.add(region);
            }
          }
        });
        editor.getCaretModel().moveToOffset(cursor.getEndOffset());
        TextRange withinBounds = cursor.intersection(TextRange.from(0, editor.getDocument().getTextLength()));
        if (withinBounds == null) withinBounds = TextRange.EMPTY_RANGE;
        editor.getSelectionModel().setSelection(withinBounds.getStartOffset(), withinBounds.getEndOffset());
        EditorSearchSession.logSelectionUpdate();
      }
      else {
        FindUtil.selectSearchResultInEditor(editor, cursor, -1);
      }
      if (adjustScrollPosition) {
        editor.getScrollingModel().scrollToCaret(ScrollType.CENTER);
      }
    } else {
      if (!SearchResults.insideVisibleArea(editor, cursor) && adjustScrollPosition) {
        LogicalPosition pos = editor.offsetToLogicalPosition(cursor.getStartOffset());
        editor.getScrollingModel().scrollTo(pos, ScrollType.CENTER);
      }
    }
  }
public void updateSelection(boolean removePreviousSelection, boolean removeAllPreviousSelections, boolean adjustScrollPosition)