forked from qt-creator/qt-creator
QmlJsEditor: Implement "Follow Symbol" for qrc paths in string literals
Task-number: QTCREATORBUG-28087 Change-Id: If1e706a96bb9cbb004f826c4d58d7d7f0c306b41 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -882,7 +882,10 @@ bool CppEditorWidget::followQrcUrl(const QTextCursor &cursor,
|
||||
if (!nodeForPath)
|
||||
return false;
|
||||
|
||||
processLinkCallback(Link(nodeForPath->filePath()));
|
||||
Link link(nodeForPath->filePath());
|
||||
link.linkTextStart = d->m_lastSemanticInfo.doc->translationUnit()->getTokenPositionInDocument(literalAst->literal_token, document());
|
||||
link.linkTextEnd = d->m_lastSemanticInfo.doc->translationUnit()->getTokenEndPositionInDocument(literalAst->literal_token, document());
|
||||
processLinkCallback(link);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -24,7 +24,10 @@
|
||||
|
||||
#include <qmljstools/qmljsindenter.h>
|
||||
#include <qmljstools/qmljstoolsconstants.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/projectnodes.h>
|
||||
#include <projectexplorer/projecttree.h>
|
||||
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
@@ -767,6 +770,25 @@ void QmlJSEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
// string literals that could refer to a file link to them
|
||||
if (auto literal = cast<const StringLiteral *>(node)) {
|
||||
const QString &text = literal->value.toString();
|
||||
if (text.startsWith("qrc:/")) {
|
||||
const ProjectExplorer::Project * const project = ProjectExplorer::ProjectTree::currentProject();
|
||||
if (project && project->rootProjectNode()) {
|
||||
const ProjectExplorer::Node * const nodeForPath = project->rootProjectNode()->findNode(
|
||||
[qrcPath = text.mid(text.indexOf(':') + 1)](ProjectExplorer::Node *n) {
|
||||
if (!n->asFileNode())
|
||||
return false;
|
||||
const auto qrcNode = dynamic_cast<ProjectExplorer::ResourceFileNode *>(n);
|
||||
return qrcNode && qrcNode->qrcPath() == qrcPath;
|
||||
});
|
||||
if (nodeForPath) {
|
||||
Link link(nodeForPath->filePath());
|
||||
link.linkTextStart = literal->firstSourceLocation().begin();
|
||||
link.linkTextEnd = literal->lastSourceLocation().end();
|
||||
processLinkCallback(link);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
Utils::Link link;
|
||||
link.linkTextStart = literal->literalToken.begin();
|
||||
link.linkTextEnd = literal->literalToken.end();
|
||||
|
Reference in New Issue
Block a user