forked from qt-creator/qt-creator
QmlDesigner: Fix crash
The nullptr does crash. We can use a proper QmlJSQuickFixAssistInterface created from the editor instead. Task-number: QDS-9573 Change-Id: I5ea2792acb311c37e1005ff039ed7110503dfb4f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Tim Jenssen <tim.jenssen@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "basetexteditmodifier.h"
|
#include "basetexteditmodifier.h"
|
||||||
|
#include "qmljseditor/qmljseditor.h"
|
||||||
|
|
||||||
#include <qmljs/qmljsmodelmanagerinterface.h>
|
#include <qmljs/qmljsmodelmanagerinterface.h>
|
||||||
#include <qmljs/parser/qmljsast_p.h>
|
#include <qmljs/parser/qmljsast_p.h>
|
||||||
@@ -111,7 +112,10 @@ bool BaseTextEditModifier::moveToComponent(int nodeOffset)
|
|||||||
if (!object)
|
if (!object)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QmlJSEditor::performComponentFromObjectDef(document->filePath().toString(), object);
|
QmlJSEditor::performComponentFromObjectDef(qobject_cast<QmlJSEditor::QmlJSEditorWidget *>(
|
||||||
|
m_textEdit),
|
||||||
|
document->filePath().toString(),
|
||||||
|
object);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -246,13 +246,16 @@ void matchComponentFromObjectDefQuickFix(const QmlJSQuickFixAssistInterface *int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void performComponentFromObjectDef(const QString &fileName, QmlJS::AST::UiObjectDefinition *objDef)
|
void performComponentFromObjectDef(QmlJSEditorWidget *editor,
|
||||||
|
const QString &fileName,
|
||||||
|
QmlJS::AST::UiObjectDefinition *objDef)
|
||||||
{
|
{
|
||||||
QmlJSRefactoringChanges refactoring(QmlJS::ModelManagerInterface::instance(),
|
QmlJSRefactoringChanges refactoring(QmlJS::ModelManagerInterface::instance(),
|
||||||
QmlJS::ModelManagerInterface::instance()->snapshot());
|
QmlJS::ModelManagerInterface::instance()->snapshot());
|
||||||
QmlJSRefactoringFilePtr current = refactoring.file(Utils::FilePath::fromString(fileName));
|
QmlJSRefactoringFilePtr current = refactoring.file(Utils::FilePath::fromString(fileName));
|
||||||
|
|
||||||
Operation operation(nullptr, objDef);
|
QmlJSQuickFixAssistInterface interface(editor, TextEditor::AssistReason::ExplicitlyInvoked);
|
||||||
|
Operation operation(&interface, objDef);
|
||||||
|
|
||||||
operation.performChanges(current, refactoring);
|
operation.performChanges(current, refactoring);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,13 @@
|
|||||||
|
|
||||||
namespace QmlJSEditor {
|
namespace QmlJSEditor {
|
||||||
|
|
||||||
|
class QmlJSEditorWidget;
|
||||||
|
|
||||||
QMLJSEDITOR_EXPORT void matchComponentFromObjectDefQuickFix(
|
QMLJSEDITOR_EXPORT void matchComponentFromObjectDefQuickFix(
|
||||||
const Internal::QmlJSQuickFixAssistInterface *interface, QuickFixOperations &result);
|
const Internal::QmlJSQuickFixAssistInterface *interface, QuickFixOperations &result);
|
||||||
|
|
||||||
QMLJSEDITOR_EXPORT void performComponentFromObjectDef
|
QMLJSEDITOR_EXPORT void performComponentFromObjectDef(QmlJSEditorWidget *editor,
|
||||||
(const QString &fileName, QmlJS::AST::UiObjectDefinition *objDef);
|
const QString &fileName,
|
||||||
|
QmlJS::AST::UiObjectDefinition *objDef);
|
||||||
|
|
||||||
} // namespace QmlJSEditor
|
} // namespace QmlJSEditor
|
||||||
|
|||||||
Reference in New Issue
Block a user