From 19f4466e3caef6d460cfe0a8d01ab9b42c48a23e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= <thorbjorn.lindeijer@nokia.com> Date: Wed, 16 Sep 2009 15:31:11 +0200 Subject: [PATCH] Tweaks to skipping of closing parenthesis and quote characters Done with mae. --- src/plugins/texteditor/basetexteditor.cpp | 29 ++++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index b766e672118..97d9b6f4fd2 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -1074,11 +1074,13 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e) QString autoText; if (d->m_autoParenthesesEnabled && d->m_document->tabSettings().m_autoParentheses) { + QChar lookAhead = characterAt(cursor.position()); foreach (QChar c, text) { QChar close; - if (c == QLatin1Char('(')) - close = QLatin1Char(')'); - else if (c == QLatin1Char('[')) + if (c == QLatin1Char('(')) { + if (!lookAhead.isLetterOrNumber() && lookAhead != c) + close = QLatin1Char(')'); + } else if (c == QLatin1Char('[')) close = QLatin1Char(']'); else if (c == QLatin1Char('\"')) close = c; @@ -1088,15 +1090,24 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e) autoText += close; } + bool skip = false; QChar first = text.at(0); - if (first == QLatin1Char(')') - || first == QLatin1Char(']')) { - if (first == characterAt(cursor.position())) { - int pos = cursor.position(); - cursor.setPosition(pos+1); - cursor.setPosition(pos, QTextCursor::KeepAnchor); + if (first == QLatin1Char(')')) { + skip = (first == lookAhead); + } else if (first == QLatin1Char(']')) { + skip = (first == lookAhead); + } else if (first == QLatin1Char('\"') || first == QLatin1Char('\'')) { + if (first == lookAhead) { + QChar lookBehind = characterAt(cursor.position()-1); + skip = (lookBehind != '\\'); } } + + if (skip) { + int pos = cursor.position(); + cursor.setPosition(pos+1); + cursor.setPosition(pos, QTextCursor::KeepAnchor); + } } QChar electricChar; if (d->m_document->tabSettings().m_autoIndent) { -- GitLab