Commit dfedba30 authored by Christian Kamm's avatar Christian Kamm
Browse files

QmlJS editor: Fix automatic quote insertion.

The new multiline string literals mixed things up.

Task-number: QTCREATORBUG-3244
Reviewed-by: Roberto Raggi
parent da308b1f
...@@ -43,7 +43,7 @@ using namespace QmlJS; ...@@ -43,7 +43,7 @@ using namespace QmlJS;
static int blockStartState(const QTextBlock &block) static int blockStartState(const QTextBlock &block)
{ {
int state = block.userState(); int state = block.previous().userState();
if (state == -1) if (state == -1)
return 0; return 0;
...@@ -181,7 +181,15 @@ bool AutoCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor, ...@@ -181,7 +181,15 @@ bool AutoCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor,
case Token::String: { case Token::String: {
const QString blockText = cursor.block().text(); const QString blockText = cursor.block().text();
const QStringRef tokenText = blockText.midRef(token.offset, token.length); const QStringRef tokenText = blockText.midRef(token.offset, token.length);
const QChar quote = tokenText.at(0); QChar quote = tokenText.at(0);
// if a string literal doesn't start with a quote, it must be multiline
if (quote != QLatin1Char('"') && quote != QLatin1Char('\'')) {
const int startState = blockStartState(cursor.block());
if (startState == Scanner::MultiLineStringDQuote)
quote = QLatin1Char('"');
else if (startState == Scanner::MultiLineStringSQuote)
quote = QLatin1Char('\'');
}
// never insert ' into string literals, it adds spurious ' when writing contractions // never insert ' into string literals, it adds spurious ' when writing contractions
if (ch == QLatin1Char('\'')) if (ch == QLatin1Char('\''))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment