From bf74d21d6c39bade8b47e8c4982325b2adb6c6c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= <thorbjorn.lindeijer@nokia.com>
Date: Tue, 22 Sep 2009 16:52:27 +0200
Subject: [PATCH] Avoid completing a closing parenthesis in the wrong place

Need to check the character to the right of the cursor.
---
 src/plugins/cppeditor/cppeditor.cpp        |  2 --
 src/plugins/cpptools/cppcodecompletion.cpp | 12 ++++++++----
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp
index 5046a8c9a21..b0caaeb35b0 100644
--- a/src/plugins/cppeditor/cppeditor.cpp
+++ b/src/plugins/cppeditor/cppeditor.cpp
@@ -1862,5 +1862,3 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source)
 
     return semanticInfo;
 }
-
-
diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp
index 4c7c0a038f5..63a4d4c6cc1 100644
--- a/src/plugins/cpptools/cppcodecompletion.cpp
+++ b/src/plugins/cpptools/cppcodecompletion.cpp
@@ -46,6 +46,7 @@
 
 #include <cplusplus/ResolveExpression.h>
 #include <cplusplus/LookupContext.h>
+#include <cplusplus/MatchingText.h>
 #include <cplusplus/Overview.h>
 #include <cplusplus/ExpressionUnderCursor.h>
 #include <cplusplus/TokenUnderCursor.h>
@@ -1510,11 +1511,14 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item)
                         if (endWithSemicolon)
                             extraChars += QLatin1Char(';');
                     } else if (autoParenthesesEnabled) {
-                        extraChars += QLatin1Char(')');
-                        --cursorOffset;
-                        if (endWithSemicolon) {
-                            extraChars += QLatin1Char(';');
+                        const QChar lookAhead = m_editor->characterAt(m_editor->position() + 1);
+                        if (MatchingText::shouldInsertMatchingText(lookAhead)) {
+                            extraChars += QLatin1Char(')');
                             --cursorOffset;
+                            if (endWithSemicolon) {
+                                extraChars += QLatin1Char(';');
+                                --cursorOffset;
+                            }
                         }
                     }
                 }
-- 
GitLab