int (@NotNull final PsiElement element, @NotNull final Editor editor) { if (isBunchOfElement(element)) { final PsiElement firstElement = getFirstElement(element); return firstElement.getTextRange().getStartOffset(); } final int offset = editor.getCaretModel().getOffset(); final int elementTextOffset = element.getTextOffset(); final Document document = editor.getDocument(); int lineNumber = document.getLineNumber(offset); while (lineNumber != document.getLineNumber(elementTextOffset)) { final String text = document.getText(TextRange.create(document.getLineStartOffset(lineNumber), document.getLineEndOffset(lineNumber))); if (StringUtil.isEmptyOrSpaces(text)) { lineNumber += 1; break; } lineNumber -= 1; } final int lineStartOffset = lineNumber == document.getLineNumber(elementTextOffset) ? elementTextOffset : document.getLineStartOffset(lineNumber); final String lineText = document .getText(TextRange.create(lineStartOffset, document.getLineEndOffset(lineNumber))); int shift = StringUtil.findFirst(lineText, CharFilter.NOT_WHITESPACE_FILTER); return lineStartOffset + shift; }