Commit 5e59605c authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

QMLEditor: changed quickfix to only activate on the type id.

parent dc73e7d1
......@@ -149,20 +149,20 @@ public:
QList<QmlJSQuickFixOperation::Ptr> ComponentFromObjectDef::match(const QmlJSQuickFixState &state)
{
QList<QmlJSQuickFixOperation::Ptr> result;
const int pos = state.currentFile().cursor().position();
QList<Node *> path = state.semanticInfo().astPath(pos);
for (int i = path.size() - 1; i >= 0; --i) {
Node *node = path.at(i);
if (UiObjectDefinition *objDef = cast<UiObjectDefinition *>(node)) {
if (!state.currentFile().isCursorOn(objDef->qualifiedTypeNameId))
return noResult();
// check that the node is not the root node
if (i > 0 && !cast<UiProgram*>(path.at(i - 1))) {
result.append(QmlJSQuickFixOperation::Ptr(new Operation(state, objDef)));
return result;
return singleResult(new Operation(state, objDef));
}
}
}
return result;
return noResult();
}
......@@ -117,6 +117,17 @@ QList<QuickFixOperation::Ptr> QmlJSQuickFixFactory::matchingOperations(QuickFixS
return QList<TextEditor::QuickFixOperation::Ptr>();
}
QList<QmlJSQuickFixOperation::Ptr> QmlJSQuickFixFactory::noResult()
{
return QList<QmlJSQuickFixOperation::Ptr>();
}
QList<QmlJSQuickFixOperation::Ptr> QmlJSQuickFixFactory::singleResult(QmlJSQuickFixOperation *operation)
{
QList<QmlJSQuickFixOperation::Ptr> result;
result.append(QmlJSQuickFixOperation::Ptr(operation));
return result;
}
QmlJSQuickFixCollector::QmlJSQuickFixCollector()
{
......
......@@ -132,6 +132,9 @@ public:
QmlJSQuickFixOperation objects.
*/
virtual QList<QmlJSQuickFixOperation::Ptr> match(const QmlJSQuickFixState &state) = 0;
static QList<QmlJSQuickFixOperation::Ptr> noResult();
static QList<QmlJSQuickFixOperation::Ptr> singleResult(QmlJSQuickFixOperation *operation);
};
namespace Internal {
......
......@@ -52,8 +52,6 @@ class SplitInitializerOp: public QmlJSQuickFixFactory
public:
virtual QList<QmlJSQuickFixOperation::Ptr> match(const QmlJSQuickFixState &state)
{
QList<QmlJSQuickFixOperation::Ptr> result;
UiObjectInitializer *objectInitializer = 0;
const int pos = state.currentFile().cursor().position();
......@@ -70,8 +68,9 @@ public:
}
if (objectInitializer)
result.append(QSharedPointer<QmlJSQuickFixOperation>(new Operation(state, objectInitializer)));
return result;
return singleResult(new Operation(state, objectInitializer));
else
return noResult();
}
private:
......
......@@ -30,6 +30,7 @@
#include "qmljsrefactoringchanges.h"
#include "qmljseditorcodeformatter.h"
#include <qmljs/parser/qmljsast_p.h>
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/tabsettings.h>
......@@ -109,11 +110,33 @@ Document::Ptr QmlJSRefactoringFile::qmljsDocument() const
return m_qmljsDocument;
}
unsigned QmlJSRefactoringFile::startOf(const QmlJS::AST::SourceLocation &loc) const
unsigned QmlJSRefactoringFile::startOf(const AST::SourceLocation &loc) const
{
return position(loc.startLine, loc.startColumn);
}
bool QmlJSRefactoringFile::isCursorOn(AST::UiObjectMember *ast) const
{
const unsigned pos = cursor().position();
return ast->firstSourceLocation().begin() <= pos
&& pos <= ast->lastSourceLocation().end();
}
bool QmlJSRefactoringFile::isCursorOn(AST::UiQualifiedId *ast) const
{
const unsigned pos = cursor().position();
if (ast->identifierToken.begin() > pos)
return false;
AST::UiQualifiedId *last = ast;
while (last->next)
last = last->next;
return pos <= ast->identifierToken.end();
}
QmlJSRefactoringChanges *QmlJSRefactoringFile::refactoringChanges() const
{
return static_cast<QmlJSRefactoringChanges *>(m_refactoringChanges);
......
......@@ -57,6 +57,9 @@ public:
*/
unsigned startOf(const QmlJS::AST::SourceLocation &loc) const;
bool isCursorOn(QmlJS::AST::UiObjectMember *ast) const;
bool isCursorOn(QmlJS::AST::UiQualifiedId *ast) const;
private:
QmlJSRefactoringChanges *refactoringChanges() const;
......
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