TextRange (@NotNull TextRange blockRange) { int nStartLine = myDocument.getLineNumber(blockRange.getStartOffset()) + 1; int nEndLine = myDocument.getLineNumber(blockRange.getEndOffset()); TextRange lastLineRange = new TextRange(myDocument.getLineStartOffset(nEndLine), myDocument.getLineEndOffset(nEndLine)); String lastLine = myDocument.getText(lastLineRange); lastLine = lastLine.substring(0, lastLine.indexOf("\"\"\"")); if (StringUtil.skipWhitespaceForward(lastLine, 0) == lastLine.length()) nEndLine -= 1; if (nEndLine < nStartLine) return null; return new TextRange(myDocument.getLineStartOffset(nStartLine), myDocument.getLineStartOffset(nEndLine)); }