From e790363fda3fe72a6706bf7228e74f847f7cb787 Mon Sep 17 00:00:00 2001 From: Roberto Raggi <roberto.raggi@nokia.com> Date: Mon, 18 Jan 2010 11:23:24 +0100 Subject: [PATCH] Check the lookahead character before inserting the matching quote or brace. --- src/plugins/qmljseditor/qmljseditor.cpp | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index 7af2fffbc8d..c627d342083 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -98,6 +98,30 @@ int blockStartState(const QTextBlock &block) else return state & 0xff; } + +bool shouldInsertMatchingText(const QChar &lookAhead) +{ + switch (lookAhead.unicode()) { + case '{': case '}': + case ']': case ')': + case ';': case ',': + case '"': case '\'': + return true; + + default: + if (lookAhead.isSpace()) + return true; + + return false; + } // switch +} + +bool shouldInsertMatchingText(const QTextCursor &tc) +{ + QTextDocument *doc = tc.document(); + return shouldInsertMatchingText(doc->characterAt(tc.selectionEnd())); +} + } // end of anonymous namespace namespace QmlJSEditor { @@ -825,6 +849,9 @@ QString QmlJSTextEditor::insertMatchingBrace(const QTextCursor &tc, const QStrin if (text.length() != 1) return QString(); + if (! shouldInsertMatchingText(tc)) + return QString(); + const QChar la = characterAt(tc.position()); const QChar ch = text.at(0); -- GitLab