diff options
author | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2021-08-18 14:57:19 +0300 |
---|---|---|
committer | Orgad Shaneh <orgads@gmail.com> | 2021-08-18 12:39:43 +0000 |
commit | c6ac773b9a2d6fc5cb581cd56785525d0a352a4a (patch) | |
tree | abf7001e6dfe4b78ae03388966dc6673ef84b640 /src/plugins/cpptools/cppcodeformatter.cpp | |
parent | 57243d4dc62db9ae4738c08c13ad84755fe23fb0 (diff) | |
download | qt-creator-c6ac773b9a2d6fc5cb581cd56785525d0a352a4a.tar.gz |
CppTools: Fix indentation of plain strings
Raw strings should not be indented, but old-style strings still should.
Amends commit ddf7f5f232d70c8598654fdad08af3064f95903f.
Fixes: QTCREATORBUG-25817
Change-Id: I7836388efb2d19b8b898c7463c7fa2d2077e80b2
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/cpptools/cppcodeformatter.cpp')
-rw-r--r-- | src/plugins/cpptools/cppcodeformatter.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/plugins/cpptools/cppcodeformatter.cpp b/src/plugins/cpptools/cppcodeformatter.cpp index ddd1079c32..639084a3ca 100644 --- a/src/plugins/cpptools/cppcodeformatter.cpp +++ b/src/plugins/cpptools/cppcodeformatter.cpp @@ -559,6 +559,7 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block) break; case string_open: + case raw_string_open: if (!m_currentToken.isStringLiteral()) { leave(); continue; @@ -672,14 +673,14 @@ void CodeFormatter::updateLineStateChange(const QTextBlock &block) saveBlockData(&next, BlockData()); } -bool CodeFormatter::isInStringLiteral(const QTextBlock &block) const +bool CodeFormatter::isInRawStringLiteral(const QTextBlock &block) const { if (!block.previous().isValid()) return false; BlockData blockData; if (!loadBlockData(block.previous(), &blockData)) return false; - return !blockData.m_endState.isEmpty() && blockData.m_endState.top().type == string_open; + return !blockData.m_endState.isEmpty() && blockData.m_endState.top().type == raw_string_open; } CodeFormatter::State CodeFormatter::state(int belowTop) const @@ -825,7 +826,7 @@ bool CodeFormatter::tryExpression(bool alsoExpression) } if (m_currentToken.isStringLiteral()) - newState = string_open; + newState = m_currentToken.kind() == T_RAW_STRING_LITERAL ? raw_string_open : string_open; if (newState != -1) { if (alsoExpression) @@ -1439,6 +1440,7 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd break; case string_open: + case raw_string_open: *paddingDepth = tokenPosition - *indentDepth; break; } @@ -1481,6 +1483,7 @@ void QtStyleCodeFormatter::adjustIndent(const Tokens &tokens, int lexerState, in } break; case string_open: + case raw_string_open: if (!tokenAt(0).isStringLiteral()) { *paddingDepth = topState.savedPaddingDepth; topState = previousState; |