TextRange (@NotNull TextRange original) { int startLine = myDocument.getLineNumber(original.getStartOffset()); int endLine = myDocument.getLineNumber(original.getEndOffset() - 1); int rangeStart = myDocument.getLineStartOffset(startLine); int rangeEnd = myDocument.getLineEndOffset(endLine); if (rangeStart > 0 && myDocument.getCharsSequence().charAt(rangeStart - 1) == '\n') rangeStart--; return new TextRange(rangeStart, rangeEnd); }