PsiElement () { int offset = myCaret.getOffset(); TextRange range = new TextRange(myCaret.getSelectionStart(), myCaret.getSelectionEnd()); if (offset == range.getEndOffset()) { offset--; } if (offset <= range.getStartOffset()) { offset++; } PsiElement comment = getCommentAtOffset(offset); if (comment == null || myCaret.hasSelection() && !range.contains(comment.getTextRange())) { return null; } return comment; }