diff options
author | Roberto Raggi <roberto.raggi@nokia.com> | 2010-01-13 13:51:01 +0100 |
---|---|---|
committer | Roberto Raggi <roberto.raggi@nokia.com> | 2010-01-13 13:54:38 +0100 |
commit | eaecfb7e06cc4bae383f79194f2619c46507c1bb (patch) | |
tree | 688e2948c8fa14445560b4b5dd1bff1f32d49c88 /src/plugins/qtscripteditor/qtscripteditor.cpp | |
parent | 7baecce079000ef85e251892fc3de1510a023592 (diff) | |
download | qt-creator-eaecfb7e06cc4bae383f79194f2619c46507c1bb.tar.gz |
Fixed auto-quote completion at the end of unfinished string literals.
Diffstat (limited to 'src/plugins/qtscripteditor/qtscripteditor.cpp')
-rw-r--r-- | src/plugins/qtscripteditor/qtscripteditor.cpp | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/src/plugins/qtscripteditor/qtscripteditor.cpp b/src/plugins/qtscripteditor/qtscripteditor.cpp index 670c5c747e..a5fe7eccee 100644 --- a/src/plugins/qtscripteditor/qtscripteditor.cpp +++ b/src/plugins/qtscripteditor/qtscripteditor.cpp @@ -402,6 +402,19 @@ void ScriptEditor::unCommentSelection() Utils::unCommentSelection(this); } +static bool isCompleteStringLiteral(const QStringRef &text) +{ + if (text.length() < 2) + return false; + + const QChar quote = text.at(0); + + if (text.at(text.length() - 1) == quote) + return text.at(text.length() - 2) != QLatin1Char('\\'); // ### not exactly. + + return false; +} + bool ScriptEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, const QString &textToInsert) const { QChar ch; @@ -442,18 +455,21 @@ bool ScriptEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, const const QList<QScriptIncrementalScanner::Token> tokens = tokenize(blockText, blockState); const int pos = cursor.columnNumber(); - int tokenIndex = tokens.size() - 1; - for (; tokenIndex != -1; --tokenIndex) { + int tokenIndex = 0; + for (; tokenIndex < tokens.size(); ++tokenIndex) { const QScriptIncrementalScanner::Token &token = tokens.at(tokenIndex); + if (pos >= token.begin()) { if (pos < token.end()) break; - else if (pos == token.end() && token.is(QScriptIncrementalScanner::Token::Comment)) + + else if (pos == token.end() && (token.is(QScriptIncrementalScanner::Token::Comment) || + token.is(QScriptIncrementalScanner::Token::String))) break; } } - if (tokenIndex != -1) { + if (tokenIndex != tokens.size()) { const QScriptIncrementalScanner::Token &token = tokens.at(tokenIndex); switch (token.kind) { @@ -461,10 +477,12 @@ bool ScriptEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, const return false; case QScriptIncrementalScanner::Token::String: { - if (ch == blockText.at(token.begin())) { - if (token.end() - 1 == pos && blockText.at(token.end() - 2) != QLatin1Char('\\')) - break; - } + const QStringRef tokenText = blockText.midRef(token.offset, token.length); + const QChar quote = tokenText.at(0); + + if (ch == quote && isCompleteStringLiteral(tokenText)) + break; + return false; } |