From 1c6e7c796bf345cea546890090c58aac15b3c8f8 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Tue, 28 Mar 2023 18:14:27 +0200 Subject: [PATCH] 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 Reviewed-by: Tim Jenssen Reviewed-by: --- .../designercore/model/basetexteditmodifier.cpp | 6 +++++- src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp | 7 +++++-- src/plugins/qmljseditor/qmljscomponentfromobjectdef.h | 7 +++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/plugins/qmldesigner/designercore/model/basetexteditmodifier.cpp b/src/plugins/qmldesigner/designercore/model/basetexteditmodifier.cpp index f07b74f8692..69c74ec6cf8 100644 --- a/src/plugins/qmldesigner/designercore/model/basetexteditmodifier.cpp +++ b/src/plugins/qmldesigner/designercore/model/basetexteditmodifier.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "basetexteditmodifier.h" +#include "qmljseditor/qmljseditor.h" #include #include @@ -111,7 +112,10 @@ bool BaseTextEditModifier::moveToComponent(int nodeOffset) if (!object) return false; - QmlJSEditor::performComponentFromObjectDef(document->filePath().toString(), object); + QmlJSEditor::performComponentFromObjectDef(qobject_cast( + m_textEdit), + document->filePath().toString(), + object); return true; } } diff --git a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp index 98713d1a367..b29d1627db5 100644 --- a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp +++ b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp @@ -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(), QmlJS::ModelManagerInterface::instance()->snapshot()); 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); } diff --git a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.h b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.h index 8ac708aed2e..72a0f50e20e 100644 --- a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.h +++ b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.h @@ -8,10 +8,13 @@ namespace QmlJSEditor { +class QmlJSEditorWidget; + QMLJSEDITOR_EXPORT void matchComponentFromObjectDefQuickFix( const Internal::QmlJSQuickFixAssistInterface *interface, QuickFixOperations &result); -QMLJSEDITOR_EXPORT void performComponentFromObjectDef - (const QString &fileName, QmlJS::AST::UiObjectDefinition *objDef); +QMLJSEDITOR_EXPORT void performComponentFromObjectDef(QmlJSEditorWidget *editor, + const QString &fileName, + QmlJS::AST::UiObjectDefinition *objDef); } // namespace QmlJSEditor