forked from qt-creator/qt-creator
qmljs: improve suggestion ordering
change matchStrength sp that a contigous prefix is always preferred
Task-number: QTCREATORBUG-10638
Change-Id: I532d93eddae1ad39157ff65e96fc6651200264ab
Change-Id: I1001f5f4b78bac84b8df8ddc4c394c68359f7821
Reviewed-by: Mitch Curtis <mitch.curtis@digia.com>
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
This commit is contained in:
@@ -654,7 +654,7 @@ int matchStrength(const QString &searchStr, const QString &str)
|
|||||||
{
|
{
|
||||||
QString::const_iterator i = searchStr.constBegin(), iEnd = searchStr.constEnd(),
|
QString::const_iterator i = searchStr.constBegin(), iEnd = searchStr.constEnd(),
|
||||||
j = str.constBegin(), jEnd = str.constEnd();
|
j = str.constBegin(), jEnd = str.constEnd();
|
||||||
bool lastWasNotUpper=true, lastWasSpacer=true, lastWasMatch = false;
|
bool lastWasNotUpper=true, lastWasSpacer=true, lastWasMatch = false, didJump = false;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
while (i != iEnd && j != jEnd) {
|
while (i != iEnd && j != jEnd) {
|
||||||
bool thisIsUpper = (*j).isUpper();
|
bool thisIsUpper = (*j).isUpper();
|
||||||
@@ -667,6 +667,7 @@ int matchStrength(const QString &searchStr, const QString &str)
|
|||||||
lastWasMatch = true;
|
lastWasMatch = true;
|
||||||
++i;
|
++i;
|
||||||
} else {
|
} else {
|
||||||
|
didJump = true;
|
||||||
lastWasMatch = false;
|
lastWasMatch = false;
|
||||||
}
|
}
|
||||||
++j;
|
++j;
|
||||||
@@ -674,9 +675,11 @@ int matchStrength(const QString &searchStr, const QString &str)
|
|||||||
lastWasSpacer = !thisIsLetterOrNumber;
|
lastWasSpacer = !thisIsLetterOrNumber;
|
||||||
}
|
}
|
||||||
if (i != iEnd)
|
if (i != iEnd)
|
||||||
return iEnd - i;
|
return i - iEnd;
|
||||||
if (j == jEnd)
|
if (j == jEnd)
|
||||||
++res;
|
++res;
|
||||||
|
if (!didJump)
|
||||||
|
res+=2;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -985,13 +985,16 @@ const SemanticInfo &QmlJSCompletionAssistInterface::semanticInfo() const
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
struct QmlJSLessThan
|
class QmlJSLessThan
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
QmlJSLessThan(const QString &searchString) : m_searchString(searchString)
|
||||||
|
{ }
|
||||||
bool operator() (const BasicProposalItem *a, const BasicProposalItem *b)
|
bool operator() (const BasicProposalItem *a, const BasicProposalItem *b)
|
||||||
{
|
{
|
||||||
if (a->order() != b->order())
|
if (a->order() != b->order())
|
||||||
return a->order() > b->order();
|
return a->order() > b->order();
|
||||||
else if (a->text().isEmpty())
|
else if (a->text().isEmpty() && ! b->text().isEmpty())
|
||||||
return true;
|
return true;
|
||||||
else if (b->text().isEmpty())
|
else if (b->text().isEmpty())
|
||||||
return false;
|
return false;
|
||||||
@@ -1001,8 +1004,14 @@ struct QmlJSLessThan
|
|||||||
return false;
|
return false;
|
||||||
else if (a->text().at(0).isLower() && b->text().at(0).isUpper())
|
else if (a->text().at(0).isLower() && b->text().at(0).isUpper())
|
||||||
return true;
|
return true;
|
||||||
|
int m1 = PersistentTrie::matchStrength(m_searchString, a->text());
|
||||||
|
int m2 = PersistentTrie::matchStrength(m_searchString, b->text());
|
||||||
|
if (m1 != m2)
|
||||||
|
return m1 > m2;
|
||||||
return a->text() < b->text();
|
return a->text() < b->text();
|
||||||
}
|
}
|
||||||
|
private:
|
||||||
|
QString m_searchString;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Anonymous
|
} // Anonymous
|
||||||
@@ -1023,9 +1032,9 @@ void QmlJSAssistProposalModel::filter(const QString &prefix)
|
|||||||
m_currentItems = newCurrentItems;
|
m_currentItems = newCurrentItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlJSAssistProposalModel::sort(const QString &)
|
void QmlJSAssistProposalModel::sort(const QString &prefix)
|
||||||
{
|
{
|
||||||
qSort(currentItems().first, currentItems().second, QmlJSLessThan());
|
qSort(currentItems().first, currentItems().second, QmlJSLessThan(prefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QmlJSAssistProposalModel::keepPerfectMatch(TextEditor::AssistReason reason) const
|
bool QmlJSAssistProposalModel::keepPerfectMatch(TextEditor::AssistReason reason) const
|
||||||
|
|||||||
Reference in New Issue
Block a user