diff --git a/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp b/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp index 8d6d80dfc08..2c40d5ea278 100644 --- a/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp +++ b/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp @@ -116,6 +116,7 @@ void TextEditorView::nodeIdChanged(const ModelNode& /*node*/, const QString &/*n void TextEditorView::selectedNodesChanged(const QList &/*selectedNodeList*/, const QList &/*lastSelectedNodeList*/) { + m_widget->jumpTextCursorToSelectedModelNode(); } void TextEditorView::customNotification(const AbstractView * /*view*/, const QString &/*identifier*/, const QList &/*nodeList*/, const QList &/*data*/) diff --git a/src/plugins/qmldesigner/components/texteditor/texteditorwidget.cpp b/src/plugins/qmldesigner/components/texteditor/texteditorwidget.cpp index ee1a749a492..91c99606a8f 100644 --- a/src/plugins/qmldesigner/components/texteditor/texteditorwidget.cpp +++ b/src/plugins/qmldesigner/components/texteditor/texteditorwidget.cpp @@ -80,4 +80,28 @@ void TextEditorWidget::updateSelectionByCursorPosition() } } +void TextEditorWidget::jumpTextCursorToSelectedModelNode() +{ + ModelNode selectedNode; + + if (!m_textEditorView->selectedModelNodes().isEmpty()) + selectedNode = m_textEditorView->selectedModelNodes().first(); + + if (selectedNode.isValid()) { + RewriterView *rewriterView = m_textEditorView->model()->rewriterView(); + + const int nodeOffset = rewriterView->nodeOffset(selectedNode); + if (nodeOffset > 0) { + const ModelNode currentSelectedNode = rewriterView-> + nodeAtTextCursorPosition(m_textEditor->editorWidget()->textCursor().position()); + + if (currentSelectedNode != selectedNode) { + int line, column; + m_textEditor->editorWidget()->convertPosition(nodeOffset, &line, &column); + m_textEditor->editorWidget()->gotoLine(line, column); + } + } + } +} + } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/texteditor/texteditorwidget.h b/src/plugins/qmldesigner/components/texteditor/texteditorwidget.h index 84cd7297f92..26eca933c9e 100644 --- a/src/plugins/qmldesigner/components/texteditor/texteditorwidget.h +++ b/src/plugins/qmldesigner/components/texteditor/texteditorwidget.h @@ -50,6 +50,7 @@ public: } QString contextHelpId() const; + void jumpTextCursorToSelectedModelNode(); private: void updateSelectionByCursorPosition();