diff options
author | Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com> | 2009-12-07 18:26:47 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com> | 2009-12-08 11:09:11 +0100 |
commit | 9839dea6bc472a6e464a0afdbbb20677e53c5afc (patch) | |
tree | 8db1d4e569168b7bdfa857321360c75f4d8ca358 /src/libs/cplusplus/BackwardsScanner.cpp | |
parent | e408159bfe13c038cbe7201e5533db74262ce0ca (diff) | |
download | qt-creator-9839dea6bc472a6e464a0afdbbb20677e53c5afc.tar.gz |
Fixed autoindent when using tabs instead of spaces
Several special cases that are handled by the CPPEditor did not take
into account code that was using tab characters.
Task-number: QTCREATORBUG-292
Reviewed-by: Roberto Raggi
Diffstat (limited to 'src/libs/cplusplus/BackwardsScanner.cpp')
-rw-r--r-- | src/libs/cplusplus/BackwardsScanner.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/libs/cplusplus/BackwardsScanner.cpp b/src/libs/cplusplus/BackwardsScanner.cpp index 7f1f6cdfe6..288d643e79 100644 --- a/src/libs/cplusplus/BackwardsScanner.cpp +++ b/src/libs/cplusplus/BackwardsScanner.cpp @@ -70,13 +70,14 @@ const SimpleToken &BackwardsScanner::fetchToken(int i) } else { ++_blocksTokenized; - const QString blockText = _block.text(); + QString blockText = _block.text(); + _text.prepend(QLatin1Char('\n')); _text.prepend(blockText); QList<SimpleToken> adaptedTokens; for (int i = 0; i < _tokens.size(); ++i) { SimpleToken t = _tokens.at(i); - t.setPosition(t.position() + blockText.length()); + t.setPosition(t.position() + blockText.length() + 1); t.setText(_text.midRef(t.position(), t.length())); adaptedTokens.append(t); } @@ -247,8 +248,9 @@ int BackwardsScanner::startOfBlock(int index) const return start; } -int BackwardsScanner::indentation(int index) const +QString BackwardsScanner::indentationString(int index) const { - SimpleToken newline = operator[](startOfLine(index + 1)); - return newline.position(); + const SimpleToken tokenAfterNewline = operator[](startOfLine(index + 1)); + const int newlinePos = qMax(0, _text.lastIndexOf(QLatin1Char('\n'), tokenAfterNewline.position())); + return _text.mid(newlinePos, tokenAfterNewline.position() - newlinePos); } |