forked from qt-creator/qt-creator
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 <eike.ziller@qt.io> Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
committed by
Tim Jenssen
parent
09f02013e5
commit
17b761ce86
@@ -55,6 +55,7 @@
|
|||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
using namespace LanguageUtils;
|
using namespace LanguageUtils;
|
||||||
using namespace QmlJS;
|
using namespace QmlJS;
|
||||||
@@ -330,6 +331,19 @@ static inline QString extractComponentFromQml(const QString &source)
|
|||||||
return result;
|
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
|
} // anonymous namespace
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
@@ -1379,7 +1393,7 @@ void TextToModelMerger::syncExpressionProperty(AbstractProperty &modelProperty,
|
|||||||
{
|
{
|
||||||
if (modelProperty.isBindingProperty()) {
|
if (modelProperty.isBindingProperty()) {
|
||||||
BindingProperty bindingProperty = modelProperty.toBindingProperty();
|
BindingProperty bindingProperty = modelProperty.toBindingProperty();
|
||||||
if (bindingProperty.expression() != javascript
|
if (!compareJavaScriptExpression(bindingProperty.expression(), javascript)
|
||||||
|| astType.isEmpty() == bindingProperty.isDynamic()
|
|| astType.isEmpty() == bindingProperty.isDynamic()
|
||||||
|| astType != bindingProperty.dynamicTypeName()) {
|
|| astType != bindingProperty.dynamicTypeName()) {
|
||||||
differenceHandler.bindingExpressionsDiffer(bindingProperty, javascript, astType);
|
differenceHandler.bindingExpressionsDiffer(bindingProperty, javascript, astType);
|
||||||
@@ -1574,7 +1588,7 @@ void ModelValidator::bindingExpressionsDiffer(BindingProperty &modelProperty,
|
|||||||
Q_UNUSED(modelProperty)
|
Q_UNUSED(modelProperty)
|
||||||
Q_UNUSED(javascript)
|
Q_UNUSED(javascript)
|
||||||
Q_UNUSED(astType)
|
Q_UNUSED(astType)
|
||||||
Q_ASSERT(modelProperty.expression() == javascript);
|
Q_ASSERT(compareJavaScriptExpression(modelProperty.expression(), javascript));
|
||||||
Q_ASSERT(modelProperty.dynamicTypeName() == astType);
|
Q_ASSERT(modelProperty.dynamicTypeName() == astType);
|
||||||
Q_ASSERT(0);
|
Q_ASSERT(0);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user