}
// get regions
final int startingWhiteSpaces = formattedLineStart
- orginalLineStart;
final IIndentationStrategy insertionStrategy;
final IStructuredDocumentRegion sdRegion = document
.getRegionAtCharacterOffset(formattedLineStart);
ITextRegion firstTokenInLine = sdRegion
.getRegionAtCharacterOffset(formattedLineStart);
int regionStart = sdRegion.getStartOffset(firstTokenInLine);
if (firstTokenInLine instanceof ITextRegionContainer) {
ITextRegionContainer container = (ITextRegionContainer) firstTokenInLine;
firstTokenInLine = container
.getRegionAtCharacterOffset(formattedLineStart);
regionStart += firstTokenInLine.getStart();
}
if (firstTokenInLine instanceof ITwigScriptRegion) {
ITwigScriptRegion scriptRegion = (ITwigScriptRegion) firstTokenInLine;
firstTokenInLine = scriptRegion.getTwigToken(formattedLineStart
- regionStart);
if (firstTokenInLine != null
&& firstTokenInLine.getStart()
+ sdRegion.getStartOffset() < orginalLineStart
&& firstTokenInLine.getType() == TwigRegionTypes.WHITESPACE) {
firstTokenInLine = scriptRegion
.getTwigToken(formattedLineStart - regionStart
+ firstTokenInLine.getLength());
}
}
// if the first char is not from this line
if (firstTokenInLine == null)
return;
/*
* if (firstTokenInLine.getStart() + sdRegion.getStartOffset() <
* originalLineInfo.getOffset() || firstTokenInLine.getType() ==
* PHPRegionTypes.WHITESPACE) { //meaning we got previos line last
* token firstTokenInLine =
* sdRegion.getRegionAtCharacterOffset(sdRegion.getStartOffset() +
* firstTokenInLine.getEnd()); }
*/
// if the next char is not from this line
// if (firstTokenInLine == null)
// return;
String firstTokenType = firstTokenInLine.getType();
/*
* if (firstTokenType == TwigRegionTypes.TWIG_CONTENT) {
* insertionStrategy = caseDefaultIndentationStrategy; } else
*/if (isTwigCommentRegion(firstTokenType)) {
insertionStrategy = commentIndentationStrategy;
} else if (firstTokenType == TwigRegionTypes.TWIG_CLOSETAG) {
insertionStrategy = phpCloseTagIndentationStrategy;
} else {
insertionStrategy = getIndentationStrategy(lineText
.charAt(startingWhiteSpaces));
}
// Fill the buffer with blanks as if we added a "\n" to the end of
// the prev element.
// insertionStrategy.placeMatchingBlanks(editor,doc,insertionStrtegyKey,resultBuffer,startOffset-1);
insertionStrategy.placeMatchingBlanks(document, resultBuffer,
lineNumber, document.getLineOffset(lineNumber));
// replace the starting spaces
final String newIndentation = resultBuffer.toString();
final String oldIndentation = lineText.substring(0,