public static int getRegionEnd(IRegion region) {
return region.getOffset() + region.getLength();
}
protected void smartIndentAfterNewLine(IDocument doc, DocumentCommand cmd) throws BadLocationException {
BlockHeuristicsScannner bhscanner = createBlockHeuristicsScanner(doc);
// Find block balances of preceding text (line start to edit cursor)
LineIndentResult nli = determineIndent(doc, bhscanner, doc.getLineOfOffset(cmd.offset), cmd.offset);
cmd.text += nli.nextLineIndent;
BlockBalanceResult blockInfo = nli.blockInfo;
if(blockInfo.unbalancedOpens > 0) {
IRegion lineRegion = doc.getLineInformationOfOffset(cmd.offset);
int lineEnd = getRegionEnd(lineRegion);
int postWsEndPos = AutoEditUtils.findEndOfWhiteSpace(doc, cmd.offset, lineEnd);
boolean hasPendingTextAfterEdit = postWsEndPos != lineEnd;
if (fCloseBlocks && !hasPendingTextAfterEdit){
if(bhscanner.shouldCloseBlock(blockInfo.rightmostUnbalancedBlockOpenOffset)) {
//close block
cmd.caretOffset = cmd.offset + cmd.text.length();
cmd.shiftsCaret = false;
String delimiter = TextUtilities.getDefaultLineDelimiter(doc);
char openChar = doc.getChar(blockInfo.rightmostUnbalancedBlockOpenOffset);
char closeChar = bhscanner.getClosingPeer(openChar);
cmd.text += delimiter + addIndent(nli.editLineIndent, blockInfo.unbalancedOpens - 1) + closeChar;
}
}
return;
}