From 308b0be678224623f5cd7131861d546b176e3a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= <thorbjorn.lindeijer@nokia.com> Date: Tue, 14 Dec 2010 14:34:57 +0100 Subject: [PATCH] Avoid skipping the closing parenthesis when completing with '(' When the user types '(' then he'll likely also type the matching ')', in which case skipping the automatic closing parenthesis is annoying because you would end up with two of them. Reviewed-by: Roberto Raggi --- src/plugins/cpptools/cppcodecompletion.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp index 0f153b43f54..8cf27fd644d 100644 --- a/src/plugins/cpptools/cppcodecompletion.cpp +++ b/src/plugins/cpptools/cppcodecompletion.cpp @@ -1947,6 +1947,11 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item, QChar t } #endif } else if (! function->isAmbiguous()) { + // When the user typed the opening parenthesis, he'll likely also type the closing one, + // in which case it would be annoying if we put the cursor after the already automatically + // inserted closing parenthesis. + const bool skipClosingParenthesis = typedChar != QLatin1Char('('); + if (completionSettings().m_spaceAfterFunctionName) extraChars += QLatin1Char(' '); extraChars += QLatin1Char('('); @@ -1966,7 +1971,7 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item, QChar t } // If the function takes no arguments, automatically place the closing parenthesis - if (item.duplicateCount == 0 && ! function->hasArguments()) { + if (item.duplicateCount == 0 && ! function->hasArguments() && skipClosingParenthesis) { extraChars += QLatin1Char(')'); if (endWithSemicolon) { extraChars += semicolon; -- GitLab