int ( final int offset, final FormattingDocumentModel documentModel, final FormatProcessor processor, final CommonCodeStyleSettings.IndentOptions indentOptions, final FormattingModel model, final WhiteSpace whiteSpace, ASTNode nodeAfter) { boolean wsContainsCaret = whiteSpace.getStartOffset() <= offset && offset < whiteSpace.getEndOffset(); int lineStartOffset = getLineStartOffset(offset, whiteSpace, documentModel); final IndentInfo indent = calcIndent(offset, documentModel, processor, whiteSpace); final String newWS = whiteSpace.generateWhiteSpace(indentOptions, lineStartOffset, indent).toString(); if (!whiteSpace.equalsToString(newWS)) { try { if (model instanceof FormattingModelEx) { ((FormattingModelEx) model).replaceWhiteSpace(whiteSpace.getTextRange(), nodeAfter, newWS); } else { model.replaceWhiteSpace(whiteSpace.getTextRange(), newWS); } } finally { model.commitChanges(); } } final int defaultOffset = offset - whiteSpace.getLength() + newWS.length(); if (wsContainsCaret) { final int ws = whiteSpace.getStartOffset() + CharArrayUtil.shiftForward(newWS, Math.max(0, lineStartOffset - whiteSpace.getStartOffset()), " \t"); return Math.max(defaultOffset, ws); } else { return defaultOffset; } }