diff options
author | Nikolai Kosjar <[email protected]> | 2017-05-08 09:47:52 +0200 |
---|---|---|
committer | Nikolai Kosjar <[email protected]> | 2017-05-23 07:43:39 +0000 |
commit | 986a518c17d93f8662e6ce20f7f3ea92dbdb05b9 (patch) | |
tree | fd842b6035274f0346cf56fbd9d97ee71a173b15 /src/libs/cplusplus | |
parent | 19a178e1b1477e1b4f3d6aaf790d52e78b6c61b8 (diff) |
C++: Handle curly braces like other brace types
Unless it balances the curly braces
* typing '{' leads to auto insertion of '}'.
* typing '}' skips already present '}'.
* removing '{' leads to auto removal of '}'.
This prevents unbalanced curly braces, which are problematic for clang.
Concrete use cases are: typing of initializer lists, lambdas, function
definitions.
Task-number: QTCREATORBUG-15073
Change-Id: Iec8c6aa5aca054455c1e1bfde3a65c4fd1f579c3
Reviewed-by: Christian Stenger <[email protected]>
Reviewed-by: David Schulz <[email protected]>
Diffstat (limited to 'src/libs/cplusplus')
-rw-r--r-- | src/libs/cplusplus/MatchingText.cpp | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/libs/cplusplus/MatchingText.cpp b/src/libs/cplusplus/MatchingText.cpp index 2033218e10e..f783d4c508e 100644 --- a/src/libs/cplusplus/MatchingText.cpp +++ b/src/libs/cplusplus/MatchingText.cpp @@ -41,7 +41,7 @@ enum { MAX_NUM_LINES = 20 }; static bool shouldOverrideChar(QChar ch) { switch (ch.unicode()) { - case ')': case ']': case ';': case '"': case '\'': + case ')': case ']': case '}': case ';': case '"': case '\'': return true; default: @@ -262,13 +262,11 @@ QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QStri if (textToProcess.isEmpty()) return QString(); - QTextCursor tc = cursor; QString text = textToProcess; - const QString blockText = tc.block().text().mid(tc.positionInBlock()); - const QString trimmedBlockText = blockText.trimmed(); - if (skipChars) { + QTextCursor tc = cursor; + const QString blockText = tc.block().text().mid(tc.positionInBlock()); *skippedChars = countSkippedChars(blockText, textToProcess); if (*skippedChars != 0) { tc.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, *skippedChars); @@ -280,9 +278,7 @@ QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QStri foreach (const QChar &ch, text) { if (ch == QLatin1Char('(')) result += QLatin1Char(')'); else if (ch == QLatin1Char('[')) result += QLatin1Char(']'); - // Handle '{' appearance within functinon call context - else if (ch == QLatin1Char('{') && !trimmedBlockText.isEmpty() && trimmedBlockText.at(0) == QLatin1Char(')')) - result += QLatin1Char('}'); + else if (ch == QLatin1Char('{')) result += QLatin1Char('}'); } return result; |