forked from qt-creator/qt-creator
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 <christian.stenger@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user