QmlJS indenter: Never touch indent of multi-line strings.

Task-number: QTCREATORBUG-6368
Change-Id: Iae68427e429e625214bc0729aaaf313dc3371570
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@nokia.com>
This commit is contained in:
Christian Kamm
2011-10-24 12:29:54 +02:00
parent f3774d0a6f
commit a9553c494e
7 changed files with 43 additions and 14 deletions

View File

@@ -70,6 +70,8 @@ void Indenter::indentBlock(QTextDocument *doc,
codeFormatter.updateStateUntil(block);
const int depth = codeFormatter.indentFor(block);
if (depth == -1)
return;
if (isElectricCharacter(typedChar)) {
// only reindent the current line when typing electric characters if the

View File

@@ -289,10 +289,8 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
}
}
void QtStyleCodeFormatter::adjustIndent(const QList<Token> &tokens, int lexerState, int *indentDepth) const
void QtStyleCodeFormatter::adjustIndent(const QList<Token> &tokens, int startLexerState, int *indentDepth) const
{
Q_UNUSED(lexerState)
State topState = state();
State previousState = state(1);
@@ -304,6 +302,12 @@ void QtStyleCodeFormatter::adjustIndent(const QList<Token> &tokens, int lexerSta
return;
}
}
// don't touch multi-line strings at all
if ((startLexerState & Scanner::MultiLineMask) == Scanner::MultiLineStringDQuote
|| (startLexerState & Scanner::MultiLineMask) == Scanner::MultiLineStringSQuote) {
*indentDepth = -1;
return;
}
const int kind = extendedTokenKind(tokenAt(0));
switch (kind) {

View File

@@ -54,7 +54,7 @@ public:
protected:
virtual void onEnter(int newState, int *indentDepth, int *savedIndentDepth) const;
virtual void adjustIndent(const QList<QmlJS::Token> &tokens, int lexerState, int *indentDepth) const;
virtual void adjustIndent(const QList<QmlJS::Token> &tokens, int startLexerState, int *indentDepth) const;
virtual void saveBlockData(QTextBlock *block, const BlockData &data) const;
virtual bool loadBlockData(const QTextBlock &block, BlockData *data) const;

View File

@@ -69,7 +69,9 @@ public:
codeFormatter.updateStateUntil(block);
do {
tabSettings.indentLine(block, codeFormatter.indentFor(block));
const int depth = codeFormatter.indentFor(block);
if (depth != -1)
tabSettings.indentLine(block, depth);
codeFormatter.updateLineStateChange(block);
block = block.next();
} while (block.isValid() && block != end);