forked from qt-creator/qt-creator
QmlDesigner: Fix id corruption on paste
When pasting model nodes, any bound expression referring to a node in the same pasted set gets fixed so that the expression refers to a pasted copy of the node instead. This fix makes it so that only fully matching ids are replaced instead of also partial id matches. The old matching broke e.g. when the paste included both "cube" and "cubeMaterial" and a binding to "cubeMaterial". Without enforcing the full id matching, the binding became "cube1Material1". Change-Id: I3c622ea946c74d59a192157ca06d096467428364 Fixes: QDS-1564 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -38,6 +38,7 @@
|
|||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QtCore/qregularexpression.h>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
@@ -45,10 +46,13 @@ static ModelNode createNodeFromNode(const ModelNode &modelNode,const QHash<QStri
|
|||||||
|
|
||||||
static QString fixExpression(const QString &expression, const QHash<QString, QString> &idRenamingHash)
|
static QString fixExpression(const QString &expression, const QHash<QString, QString> &idRenamingHash)
|
||||||
{
|
{
|
||||||
|
const QString pattern("\\b%1\\b"); // Match only full ids
|
||||||
QString newExpression = expression;
|
QString newExpression = expression;
|
||||||
foreach (const QString &id, idRenamingHash.keys()) {
|
const auto keys = idRenamingHash.keys();
|
||||||
if (newExpression.contains(id))
|
for (const QString &id : keys) {
|
||||||
newExpression = newExpression.replace(id, idRenamingHash.value(id));
|
QRegularExpression re(pattern.arg(id));
|
||||||
|
if (newExpression.contains(re))
|
||||||
|
newExpression = newExpression.replace(re, idRenamingHash.value(id));
|
||||||
}
|
}
|
||||||
return newExpression;
|
return newExpression;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user