diff options
author | Nikolai Kosjar <[email protected]> | 2018-02-05 13:17:08 +0100 |
---|---|---|
committer | Nikolai Kosjar <[email protected]> | 2018-02-08 14:45:20 +0000 |
commit | 06294002887bffce69ecb59efb3f051542283d54 (patch) | |
tree | 31b65ee48977e17f701298b0bcbe81039a1b78c3 /src/libs/cplusplus | |
parent | 65cd490021580c03068e2a7f7d4d936c4d220a75 (diff) |
C++: Do not auto-insert '}' after class/struct/enum/union
...when typing the opening brace. This restores the initial behavior
from version 4.3.
Not auto-inserting the closing brace allows the user to press Enter to
get "};" completed.
Change-Id: I8c62a08433a947e28f0555338a5fb8eeeae11bea
Task-number: QTCREATORBUG-18872
Reviewed-by: Ivan Donchevskii <[email protected]>
Diffstat (limited to 'src/libs/cplusplus')
-rw-r--r-- | src/libs/cplusplus/MatchingText.cpp | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/src/libs/cplusplus/MatchingText.cpp b/src/libs/cplusplus/MatchingText.cpp index e6973ee3942..2909b164e16 100644 --- a/src/libs/cplusplus/MatchingText.cpp +++ b/src/libs/cplusplus/MatchingText.cpp @@ -314,6 +314,50 @@ static bool allowAutoClosingBraceByLookahead(const QTextCursor &cursor) return false; } +static bool isRecordLikeToken(const Token &token) +{ + return token.is(T_CLASS) + || token.is(T_STRUCT) + || token.is(T_UNION) + || token.is(T_ENUM); +} + +static bool isRecordLikeToken(const BackwardsScanner &tokens, int index) +{ + if (index < tokens.size() - 1) + return isRecordLikeToken(tokens[index]); + return false; +} + +static bool recordLikeHasToFollowToken(const Token &token) +{ + return token.is(T_SEMICOLON) + || token.is(T_LBRACE) // e.g. class X { + || token.is(T_RBRACE) // e.g. function definition + || token.is(T_EOF_SYMBOL); +} + +static bool recordLikeMightFollowToken(const Token &token) +{ + return token.is(T_IDENTIFIER) // e.g. macro like QT_END_NAMESPACE + || token.is(T_ANGLE_STRING_LITERAL) // e.g. #include directive + || token.is(T_STRING_LITERAL) // e.g. #include directive + || token.isComment(); +} + +static bool isAfterRecordLikeDefinition(const BackwardsScanner &tokens, int index) +{ + for (;; --index) { + if (recordLikeHasToFollowToken(tokens[index])) + return isRecordLikeToken(tokens, index + 1); + + if (recordLikeMightFollowToken(tokens[index]) && isRecordLikeToken(tokens, index + 1)) + return true; + } + + return false; +} + static bool allowAutoClosingBrace(const QTextCursor &cursor, MatchingText::IsNextBlockDeeperIndented isNextIndented) { @@ -329,6 +373,9 @@ static bool allowAutoClosingBrace(const QTextCursor &cursor, if (isAfterNamespaceDefinition(tokens, index)) return false; + if (isAfterRecordLikeDefinition(tokens, index)) + return false; + const QTextBlock block = cursor.block(); if (isEmptyOrWhitespace(block.text())) return allowAutoClosingBraceAtEmptyLine(cursor.block(), isNextIndented); @@ -555,7 +602,7 @@ QString MatchingText::insertParagraphSeparator(const QTextCursor &cursor) if (current.is(T_EOF_SYMBOL)) break; - if (current.is(T_CLASS) || current.is(T_STRUCT) || current.is(T_UNION) || current.is(T_ENUM)) { + if (isRecordLikeToken(current)) { // found a class key. QString str = QLatin1String("};"); |