forked from qt-creator/qt-creator
C++: Do not auto-insert '}' after control flow constructs
...as this rather gets in the way.
As before, pressing ENTER after { will still auto insert } on the next
line.
Fixes: QTCREATORBUG-18872
Change-Id: I8ee082962b5ee82781e51c3e5ee146343f808332
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
@@ -358,6 +358,32 @@ static bool isAfterRecordLikeDefinition(const BackwardsScanner &tokens, int inde
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool isControlFlowKeywordRequiringParentheses(const Token &token)
|
||||
{
|
||||
return token.is(T_IF)
|
||||
|| token.is(T_WHILE)
|
||||
|| token.is(T_FOR)
|
||||
|| token.is(T_SWITCH)
|
||||
|| token.is(T_CATCH);
|
||||
}
|
||||
|
||||
static bool isAfterControlFlow(const BackwardsScanner &tokens, int index)
|
||||
{
|
||||
const Token &token = tokens[index];
|
||||
if (token.is(T_DO) || token.is(T_ELSE) || token.is(T_TRY))
|
||||
return true;
|
||||
|
||||
if (token.is(T_RPAREN)) {
|
||||
const int startIndex = index + 1;
|
||||
const int matchingBraceIndex = tokens.startOfMatchingBrace(startIndex);
|
||||
if (matchingBraceIndex == startIndex)
|
||||
return false; // No matching paren found.
|
||||
return isControlFlowKeywordRequiringParentheses(tokens[matchingBraceIndex - 1]);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool allowAutoClosingBrace(const QTextCursor &cursor,
|
||||
MatchingText::IsNextBlockDeeperIndented isNextIndented)
|
||||
{
|
||||
@@ -370,6 +396,9 @@ static bool allowAutoClosingBrace(const QTextCursor &cursor,
|
||||
if (tokens[index].isStringLiteral())
|
||||
return false;
|
||||
|
||||
if (isAfterControlFlow(tokens, index))
|
||||
return false;
|
||||
|
||||
if (isAfterNamespaceDefinition(tokens, index))
|
||||
return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user