forked from qt-creator/qt-creator
QmlJS: Improve completion for object bindings with 'on'.
Done-with: Erik Verbruggen
This commit is contained in:
@@ -17,6 +17,7 @@ using namespace QmlJS;
|
||||
CompletionContextFinder::CompletionContextFinder(const QTextCursor &cursor)
|
||||
: m_cursor(cursor)
|
||||
, m_colonCount(-1)
|
||||
, m_behaviorBinding(false)
|
||||
{
|
||||
QTextBlock lastBlock = cursor.block();
|
||||
if (lastBlock.next().isValid())
|
||||
@@ -90,6 +91,7 @@ void CompletionContextFinder::checkBinding()
|
||||
int i = m_startTokenIndex;
|
||||
int colonCount = 0;
|
||||
bool delimiterFound = false;
|
||||
bool firstToken = true;
|
||||
while (!delimiterFound) {
|
||||
if (i < 0) {
|
||||
if (!readLine())
|
||||
@@ -113,11 +115,17 @@ void CompletionContextFinder::checkBinding()
|
||||
++colonCount;
|
||||
break;
|
||||
|
||||
case Token::Identifier:
|
||||
if (firstToken && yyLine->midRef(token.begin(), token.length) == QLatin1String("on"))
|
||||
m_behaviorBinding = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
--i;
|
||||
firstToken = false;
|
||||
}
|
||||
|
||||
YY_RESTORE();
|
||||
@@ -145,6 +153,15 @@ bool CompletionContextFinder::isInRhsOfBinding() const
|
||||
return isInQmlContext() && m_colonCount == 1;
|
||||
}
|
||||
|
||||
/*!
|
||||
\return true if the cursor after "Type on" in the left hand side
|
||||
of a binding, false otherwise.
|
||||
*/
|
||||
bool CompletionContextFinder::isAfterOnInLhsOfBinding() const
|
||||
{
|
||||
return isInLhsOfBinding() && m_behaviorBinding;
|
||||
}
|
||||
|
||||
int CompletionContextFinder::findOpeningBrace(int startTokenIndex)
|
||||
{
|
||||
YY_SAVE();
|
||||
@@ -211,8 +228,3 @@ int CompletionContextFinder::findOpeningBrace(int startTokenIndex)
|
||||
YY_RESTORE();
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool CompletionContextFinder::inQmlBindingRhs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ public:
|
||||
bool isInLhsOfBinding() const;
|
||||
bool isInRhsOfBinding() const;
|
||||
|
||||
bool isAfterOnInLhsOfBinding() const;
|
||||
|
||||
private:
|
||||
int findOpeningBrace(int startTokenIndex);
|
||||
void getQmlObjectTypeName(int startTokenIndex);
|
||||
@@ -33,6 +35,7 @@ private:
|
||||
|
||||
int m_startTokenIndex;
|
||||
int m_colonCount;
|
||||
bool m_behaviorBinding;
|
||||
};
|
||||
|
||||
} // namespace QmlJS
|
||||
|
||||
@@ -650,8 +650,6 @@ int CodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
||||
|
||||
bool doGlobalCompletion = true;
|
||||
if (contextFinder.isInLhsOfBinding() && qmlScopeType) {
|
||||
qDebug() << "LHS of binding!";
|
||||
|
||||
doGlobalCompletion = false;
|
||||
EnumerateProperties enumerateProperties(&context);
|
||||
enumerateProperties.setGlobalCompletion(true);
|
||||
@@ -662,7 +660,9 @@ int CodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
||||
|
||||
TextEditor::CompletionItem item(this);
|
||||
item.text = it.key();
|
||||
item.data = QString(it.key() + QLatin1String(": "));
|
||||
item.data = it.key();
|
||||
if (!contextFinder.isAfterOnInLhsOfBinding())
|
||||
item.data = QString(item.data.toString() + QLatin1String(": "));
|
||||
item.icon = symbolIcon;
|
||||
m_completions.append(item);
|
||||
}
|
||||
@@ -673,12 +673,6 @@ int CodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
||||
|
||||
TextEditor::CompletionItem item(this);
|
||||
item.text = it.key();
|
||||
QString data = it.key();
|
||||
data.append(QLatin1String(" {\n"));
|
||||
data.append(QChar::ObjectReplacementCharacter);
|
||||
data.append(QChar::ObjectReplacementCharacter);
|
||||
data.append(QLatin1String("\n}"));
|
||||
item.data = data;
|
||||
item.icon = symbolIcon;
|
||||
m_completions.append(item);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user