boolean (Editor editor, PsiElement psiElement, boolean isModified) { if (isModified) { return false; } final CaretModel caretModel = editor.getCaretModel(); PsiElement atCaret = psiElement.getContainingFile().findElementAt(caretModel.getOffset()); if (atCaret instanceof PsiWhiteSpace) { atCaret = atCaret.getPrevSibling(); } final PsiElement comment = PsiTreeUtil.getParentOfType(atCaret, PsiComment.class, false); if (comment != null) { SmartEnterUtil.plainEnter(editor); editor.getDocument().insertString(caretModel.getOffset(), "# "); caretModel.moveToOffset(caretModel.getOffset() + 2); return true; } return false; }