From 17b761ce86e9fdfadff49b35858533d06ba0d05b Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Wed, 15 Nov 2017 15:43:28 +0100 Subject: [PATCH] QmlDesigner: Ignore indentation for multi line expressions If expressions cover multiple lines they might be altered by the indenter. This means the expression differs slighlty in white spaces. This did assert before, but is a false alarm. For now we just treat the white spaces in th beginning of the line as a special case. Eventually we have to fully normalize expressions. Task-number: QTCREATORBUG-19284 Change-Id: Icc57ef08d1c889deded7cca08ccfba66f09f3115 Reviewed-by: Eike Ziller Reviewed-by: Tim Jenssen --- .../designercore/model/texttomodelmerger.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp b/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp index 47ce2bad158..6255fd85fd3 100644 --- a/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp +++ b/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp @@ -55,6 +55,7 @@ #include #include #include +#include using namespace LanguageUtils; using namespace QmlJS; @@ -330,6 +331,19 @@ static inline QString extractComponentFromQml(const QString &source) return result; } +static QString normalizeJavaScriptExpression(const QString &expression) +{ + static const QRegularExpression regExp("\\n(\\s)+"); + + QString result = expression; + return result.replace(regExp, "\n"); +} + +static bool compareJavaScriptExpression(const QString &expression1, const QString &expression2) +{ + return normalizeJavaScriptExpression(expression1) == normalizeJavaScriptExpression(expression2); +} + } // anonymous namespace namespace QmlDesigner { @@ -1379,7 +1393,7 @@ void TextToModelMerger::syncExpressionProperty(AbstractProperty &modelProperty, { if (modelProperty.isBindingProperty()) { BindingProperty bindingProperty = modelProperty.toBindingProperty(); - if (bindingProperty.expression() != javascript + if (!compareJavaScriptExpression(bindingProperty.expression(), javascript) || astType.isEmpty() == bindingProperty.isDynamic() || astType != bindingProperty.dynamicTypeName()) { differenceHandler.bindingExpressionsDiffer(bindingProperty, javascript, astType); @@ -1574,7 +1588,7 @@ void ModelValidator::bindingExpressionsDiffer(BindingProperty &modelProperty, Q_UNUSED(modelProperty) Q_UNUSED(javascript) Q_UNUSED(astType) - Q_ASSERT(modelProperty.expression() == javascript); + Q_ASSERT(compareJavaScriptExpression(modelProperty.expression(), javascript)); Q_ASSERT(modelProperty.dynamicTypeName() == astType); Q_ASSERT(0); }