TextRange (@NotNull PsiFile file) { final CharSequence contents = file.getViewProvider().getContents(); int start; boolean lineFeedNext = false; for (start = contents.length() - 1; start >= 0; start--) { final char c = contents.charAt(start); if (" \t\f\n\r".indexOf(c) < 0 && !(c == '\\' && (lineFeedNext || start == contents.length() - 1))) { break; } lineFeedNext = c == '\n'; } return new TextRange(start + 1, contents.length()); }