void (@NotNull InsertionContext context) { Editor editor = context.getEditor(); final FoldingModel foldingModel = editor.getFoldingModel(); foldingModel.runBatchFoldingOperation(() -> { FoldRegion[] regions = foldingModel.getAllFoldRegions(); for (FoldRegion region : regions) { foldingModel.removeFoldRegion(region); } }); final Document document = editor.getDocument(); final int startOffset = context.getStartOffset(); document.replaceString(startOffset, document.getTextLength(), myProjectPath); final Project project = context.getProject(); PsiDocumentManager.getInstance(project).commitDocument(document); foldingModel.runBatchFoldingOperationDoNotCollapseCaret(() -> { FoldRegion region = foldingModel.addFoldRegion(startOffset, startOffset + myProjectPath.length(), myProjectName); if (region != null) { region.setExpanded(false); } }); }