private static void writeActionForCaret(Caret startCaret, @NotNull Editor editor, @NotNull PsiFile file, @NotNull Runnable command) {
    runForCaret(startCaret, editor, () -> {
      CaretModel model = editor.getCaretModel();
      if (model.getCaretCount() == 0) {
        WriteCommandAction.writeCommandAction(editor.getProject(), file).run(() -> command.run());
      }
      else {
        DocumentUtil.writeInRunUndoTransparentAction(command);
      }
    });
  }
private static void writeActionForCaret(Caret startCaret, @NotNull Editor editor, @NotNull PsiFile file, @NotNull Runnable command)