int (int blankLinesNumber, int startOffset) { int startLine = myDocument.getLineNumber(startOffset); if (startLine <= 0) { return 0; } CharSequence text = myDocument.getCharsSequence(); for (int i = myDocument.getLineStartOffset(startLine - 1) - 1; i >= 0; i = CharArrayUtil.lastIndexOf(text, "\n", i - 1)) { if (--blankLinesNumber <= 0) { return i + 1; } } return 0; }