void (@NotNull PsiCodeBlock body, @NotNull Editor newEditor) { PsiElement l = PsiTreeUtil.skipWhitespacesForward(body.getLBrace()); PsiElement r = PsiTreeUtil.skipWhitespacesBackward(body.getRBrace()); if (l != null && r != null) { int start = l.getTextRange().getStartOffset(); int end = r.getTextRange().getEndOffset(); newEditor.getCaretModel().moveToOffset(Math.max(start, end)); if (end < start) { newEditor.getCaretModel().moveToOffset(end + 1); CodeStyleManager styleManager = CodeStyleManager.getInstance(body.getProject()); PsiFile containingFile = body.getContainingFile(); final String lineIndent = styleManager.getLineIndent(containingFile, end); PsiDocumentManager manager = PsiDocumentManager.getInstance(body.getProject()); manager.doPostponedOperationsAndUnblockDocument(newEditor.getDocument()); EditorModificationUtilEx.insertStringAtCaret(newEditor, lineIndent); EditorModificationUtilEx.insertStringAtCaret(newEditor, "\n", false, false); } else { //correct position caret for groovy and java methods if (body.getParent() instanceof PsiMethod) { final PsiGenerationInfo<PsiMethod> info = OverrideImplementUtil.createGenerationInfo((PsiMethod)body.getParent()); info.positionCaret(newEditor, true); } } newEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); } }