int (Language language, @NotNull Document document, @NotNull Editor editor, int offset) { final CharSequence docChars = document.getCharsSequence(); int indentStart = CharArrayUtil.shiftBackwardUntil(docChars, offset - 1, "\n") + 1; int indentEnd = CharArrayUtil.shiftForward(docChars, indentStart, " \t"); String newIndent = CodeStyle.getLineIndent(editor, language, offset, false); if (newIndent == null) { return -1; } if (Strings.areSameInstance(newIndent, LineIndentProvider.DO_NOT_ADJUST)) { return offset; } int delta = newIndent.length() - (indentEnd - indentStart); document.replaceString(indentStart, indentEnd, newIndent); return offset <= indentEnd ? (indentStart + newIndent.length()) : (offset + delta); }