@ApiStatus.Internal
  public static boolean strip(@NotNull Document document, boolean inChangedLinesOnly, boolean skipCaretLines) {
    if (document instanceof DocumentWindow) {
      document = ((DocumentWindow)document).getDelegate();
    }
    if (!(document instanceof DocumentImpl)) {
      return true;
    }
    List<Editor> activeEditors = getActiveEditors(document);

    final List<Caret> carets = new ArrayList<>();
    for (Editor activeEditor : activeEditors) {
      carets.addAll(activeEditor.getCaretModel().getAllCarets());
    }
    final List<VisualPosition> visualCarets = new ArrayList<>(carets.size());
    int[] caretOffsets = new int[carets.size()];
    for (int i = 0; i < carets.size(); i++) {
      Caret caret = carets.get(i);
      visualCarets.add(caret.getVisualPosition());
      caretOffsets[i] = caret.getOffset();
    }

    boolean markAsNeedsStrippingLater = ((DocumentImpl)document)
      .stripTrailingSpaces(getProject(document, activeEditors), inChangedLinesOnly, skipCaretLines ? caretOffsets : null);

    if (!activeEditors.isEmpty() && !ShutDownTracker.isShutdownHookRunning()) {
      runBatchCaretOperation(activeEditors, () -> {
        for (int i = 0; i < carets.size(); i++) {
          Caret caret = carets.get(i);
          if (caret.isValid()) {
            caret.moveToVisualPosition(visualCarets.get(i));
          }
        }
      });
    }

    return !markAsNeedsStrippingLater;
  }
@ApiStatus.Internal
  public static boolean strip(@NotNull Document document, boolean inChangedLinesOnly, boolean skipCaretLines)