diff --git a/src/plugins/qmldesigner/qmldesignerplugin.cpp b/src/plugins/qmldesigner/qmldesignerplugin.cpp index c197ad66d6d..447746f26a0 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.cpp +++ b/src/plugins/qmldesigner/qmldesignerplugin.cpp @@ -347,10 +347,22 @@ void QmlDesignerPlugin::resetModelSelection() currentDesignDocument()->rewriterView()->setSelectedModelNodes(QList()); } +static QmlJS::Document::Ptr documentForFilePath(const QString &filePath) +{ + QmlJS::Document::Ptr document = QmlJS::ModelManagerInterface::instance()->snapshot().document(filePath); + if (!document) { + document = QmlJS::Document::create(filePath, QmlJS::Language::Qml); + QmlJS::ModelManagerInterface::instance()->snapshot().insert(document); + } + + return document; +} + static bool checkIfEditorIsQtQuick(Core::IEditor *editor) { + if (editor) if (editor && editor->document()->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID) { - QmlJS::Document::Ptr document = QmlJS::ModelManagerInterface::instance()->snapshot().document(editor->document()->filePath()); + QmlJS::Document::Ptr document = documentForFilePath(editor->document()->filePath()); if (!document.isNull()) return document->language() == QmlJS::Language::QmlQtQuick1 || document->language() == QmlJS::Language::QmlQtQuick2