QmlDesigner: Move cursor to selected item

When an item is selected in the navigator we move the cursor.

Change-Id: Ia6d41e4d7bdf38688cf0cd73f134c349126eb68e
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Thomas Hartmann
2017-01-04 14:19:52 +01:00
parent e540f2eda5
commit c27d7c00d6
3 changed files with 26 additions and 0 deletions

View File

@@ -116,6 +116,7 @@ void TextEditorView::nodeIdChanged(const ModelNode& /*node*/, const QString &/*n
void TextEditorView::selectedNodesChanged(const QList<ModelNode> &/*selectedNodeList*/, void TextEditorView::selectedNodesChanged(const QList<ModelNode> &/*selectedNodeList*/,
const QList<ModelNode> &/*lastSelectedNodeList*/) const QList<ModelNode> &/*lastSelectedNodeList*/)
{ {
m_widget->jumpTextCursorToSelectedModelNode();
} }
void TextEditorView::customNotification(const AbstractView * /*view*/, const QString &/*identifier*/, const QList<ModelNode> &/*nodeList*/, const QList<QVariant> &/*data*/) void TextEditorView::customNotification(const AbstractView * /*view*/, const QString &/*identifier*/, const QList<ModelNode> &/*nodeList*/, const QList<QVariant> &/*data*/)

View File

@@ -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 } // namespace QmlDesigner

View File

@@ -50,6 +50,7 @@ public:
} }
QString contextHelpId() const; QString contextHelpId() const;
void jumpTextCursorToSelectedModelNode();
private: private:
void updateSelectionByCursorPosition(); void updateSelectionByCursorPosition();