Commit 0bb575b1 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Create a link for the QML/JS expression under cursor.

parent 7c887960
......@@ -835,6 +835,44 @@ void QmlJSTextEditor::createToolBar(QmlJSEditorEditable *editable)
TextEditor::BaseTextEditor::Link QmlJSTextEditor::findLinkAt(const QTextCursor &cursor, bool /*resolveTarget*/)
{
Link link;
const SemanticInfo semanticInfo = m_semanticInfo;
if (semanticInfo.document) {
CollectASTNodes nodes;
nodes.accept(semanticInfo.document->ast());
const unsigned cursorPosition = cursor.position();
foreach (AST::UiQualifiedId *q, nodes.qualifiedIds) {
if (cursorPosition >= q->identifierToken.begin()) {
for (AST::UiQualifiedId *tail = q; tail; tail = tail->next) {
if (! tail->next && cursorPosition <= tail->identifierToken.end()) {
link.begin = tail->identifierToken.begin();
link.end = tail->identifierToken.end();
return link;
}
}
}
}
foreach (AST::IdentifierExpression *id, nodes.identifiers) {
if (cursorPosition >= id->identifierToken.begin() && cursorPosition <= id->identifierToken.end()) {
link.begin = id->firstSourceLocation().begin();
link.end = id->lastSourceLocation().end();
return link;
}
}
foreach (AST::FieldMemberExpression *mem, nodes.fieldMembers) {
if (mem->name && cursorPosition >= mem->identifierToken.begin() && cursorPosition <= mem->identifierToken.end()) {
link.begin = mem->lastSourceLocation().begin();
link.end = mem->lastSourceLocation().end();
return link;
}
}
}
return link;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment