Fixed indentation of QML/JS multi line comments

This commit is contained in:
Roberto Raggi
2010-01-15 11:57:04 +01:00
parent bc6d14828a
commit 7215c212e3

View File

@@ -487,24 +487,36 @@ bool QScriptIndenter::bottomLineStartsInMultilineComment()
*/ */
int QScriptIndenter::indentWhenBottomLineStartsInMultiLineComment() int QScriptIndenter::indentWhenBottomLineStartsInMultiLineComment()
{ {
int k = yyLine->lastIndexOf(QLatin1String("/*")); QTextBlock block = yyProgram.lastBlock().previous();
QString blockText;
for (; block.isValid(); block = block.previous()) {
blockText = block.text();
if (! isOnlyWhiteSpace(blockText))
break;
}
const QString codeLine = trimmedCodeLine(blockText);
int k = codeLine.lastIndexOf(QLatin1String("/*"));
if (k == -1) { if (k == -1) {
/* /*
We found a normal text line in a comment. Align the We found a normal text line in a comment. Align the
bottom line with the text on this line. bottom line with the text on this line.
*/ */
return indentOfLine(*yyLine); return indentOfLine(codeLine);
} else { } else {
/* /*
The C-style comment starts on this line. If there is The C-style comment starts on this line. If there is
text on the same line, align with it. Otherwise, align text on the same line, align with it. Otherwise, align
with the slash-aster plus a given offset. with the slash-aster plus a given offset.
*/ */
int indent = columnForIndex(*yyLine, k); int indent = columnForIndex(codeLine, k);
k += 2; k += 2;
while (k < yyLine->length()) { while (k < yyLine->length()) {
if (!yyLine->at(k).isSpace()) if (!codeLine.at(k).isSpace())
return columnForIndex(*yyLine, k); return columnForIndex(codeLine, k);
k++; k++;
} }
return indent + ppCommentOffset; return indent + ppCommentOffset;