forked from qt-creator/qt-creator
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:
@@ -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*/)
|
||||||
|
@@ -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
|
||||||
|
@@ -50,6 +50,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString contextHelpId() const;
|
QString contextHelpId() const;
|
||||||
|
void jumpTextCursorToSelectedModelNode();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateSelectionByCursorPosition();
|
void updateSelectionByCursorPosition();
|
||||||
|
Reference in New Issue
Block a user