private static void moveCaret(Editor editor, int toOffset) {
    Caret caret = editor.getCaretModel().getCurrentCaret();
    caret.removeSelection();
    caret.moveToOffset(toOffset);
    FoldingModel foldingModel = editor.getFoldingModel();
    FoldRegion region = foldingModel.getCollapsedRegionAtOffset(toOffset);
    if (region != null) {
      foldingModel.runBatchFoldingOperation(() -> region.setExpanded(true));
    }
    if (caret == editor.getCaretModel().getPrimaryCaret()) {
      editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
    }
  }
private static void moveCaret(Editor editor, int toOffset)