From c17edee606e9a18f296f3ce139a0a932be72a523 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= <thorbjorn.lindeijer@nokia.com>
Date: Wed, 16 Sep 2009 17:31:17 +0200
Subject: [PATCH] Only auto-insert when the text right of the cursor seems
 unrelated

To avoid bothering people who are trying to type an expression that is
already partly there.
---
 src/plugins/texteditor/basetexteditor.cpp | 32 ++++++++++++++---------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index bde4bb569d0..51ded1681aa 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -1074,19 +1074,27 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e)
 
         if (d->m_autoParenthesesEnabled && d->m_document->tabSettings().m_autoParentheses) {
             QChar lookAhead = characterAt(cursor.position());
-            foreach (QChar c, text) {
-                QChar close;
-                if (c == QLatin1Char('(')) {
-                    if (!lookAhead.isLetterOrNumber() && lookAhead != c)
+            if (lookAhead.isSpace() // Only auto-insert when the text right of the cursor seems unrelated
+                || lookAhead == QLatin1Char('{')
+                || lookAhead == QLatin1Char('}')
+                || lookAhead == QLatin1Char(']')
+                || lookAhead == QLatin1Char(')')
+                || lookAhead == QLatin1Char(';')
+                || lookAhead == QLatin1Char(',')
+                ) {
+                foreach (QChar c, text) {
+                    QChar close;
+                    if (c == QLatin1Char('(')) {
                         close = QLatin1Char(')');
-                } else if (c == QLatin1Char('['))
-                    close = QLatin1Char(']');
-                else if (c == QLatin1Char('\"'))
-                    close = c;
-                else if (c == QLatin1Char('\''))
-                    close = c;
-                if (!close.isNull())
-                    autoText += close;
+                    } else if (c == QLatin1Char('['))
+                        close = QLatin1Char(']');
+                    else if (c == QLatin1Char('\"'))
+                        close = c;
+                    else if (c == QLatin1Char('\''))
+                        close = c;
+                    if (!close.isNull())
+                        autoText += close;
+                }
             }
 
             bool skip = false;
-- 
GitLab