void (@NotNull Caret caret) { int caretOffset = caret.getOffset(); Editor editor = caret.getEditor(); FoldRegion foldRegion = editor.getFoldingModel().getCollapsedRegionAtOffset(caretOffset - 1); if (foldRegion instanceof CustomFoldRegion && foldRegion.getEndOffset() == caretOffset) { editor.getDocument().deleteString(foldRegion.getStartOffset(), foldRegion.getEndOffset()); } }