private static void doBackSpaceAtCaret(@NotNull Editor editor) {
    VisualPosition caretPosition = editor.getCaretModel().getVisualPosition();
    if (caretPosition.column > 0 &&
        editor.getInlayModel().hasInlineElementAt(new VisualPosition(caretPosition.line, caretPosition.column - 1))) {
      editor.getCaretModel().moveCaretRelatively(-1, 0, false, false, EditorUtil.isCurrentCaretPrimary(editor));
      return;
    }

    int lineNumber = editor.getCaretModel().getLogicalPosition().line;
    int colNumber = editor.getCaretModel().getLogicalPosition().column;
    Document document = editor.getDocument();
    int offset = editor.getCaretModel().getOffset();
    if(colNumber > 0) {
      if(EditorModificationUtil.calcAfterLineEnd(editor) > 0) {
        int columnShift = -1;
        editor.getCaretModel().moveCaretRelatively(columnShift, 0, false, false, true);
      }
      else {
        editor.getSelectionModel().removeSelection();

        Runnable runnable = () -> {
          FoldRegion region = editor.getFoldingModel().getCollapsedRegionAtOffset(offset - 1);
          if (region != null && region.shouldNeverExpand()) {
            document.deleteString(region.getStartOffset(), region.getEndOffset());
            editor.getCaretModel().moveToOffset(region.getStartOffset());
          }
          else {
            int prevOffset = DocumentUtil.getPreviousCodePointOffset(document, offset);
            if (prevOffset >= 0) {
              document.deleteString(prevOffset, offset);
            }
          }
          EditorModificationUtilEx.scrollToCaret(editor);
        };
        EditorUtil.runWithAnimationDisabled(editor, runnable);
      }
    }
    else if(lineNumber > 0) {
      int separatorLength = document.getLineSeparatorLength(lineNumber - 1);
      int lineEnd = document.getLineEndOffset(lineNumber - 1) + separatorLength;
      document.deleteString(lineEnd - separatorLength, lineEnd);
      editor.getCaretModel().moveToOffset(lineEnd - separatorLength);
      EditorModificationUtil.scrollToCaret(editor);
      editor.getSelectionModel().removeSelection();
      // Do not group delete newline and other deletions.
      CommandProcessor commandProcessor = CommandProcessor.getInstance();
      commandProcessor.setCurrentCommandGroupId(null);
    }
  }
private static void doBackSpaceAtCaret(@NotNull Editor editor)