Commit 4bd3f2a6 authored by Fawzi Mohamed's avatar Fawzi Mohamed

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: default avatarMitch Curtis <mitch.curtis@digia.com>
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent f270f975
......@@ -654,7 +654,7 @@ int matchStrength(const QString &searchStr, const QString &str)
{
QString::const_iterator i = searchStr.constBegin(), iEnd = searchStr.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;
while (i != iEnd && j != jEnd) {
bool thisIsUpper = (*j).isUpper();
......@@ -667,6 +667,7 @@ int matchStrength(const QString &searchStr, const QString &str)
lastWasMatch = true;
++i;
} else {
didJump = true;
lastWasMatch = false;
}
++j;
......@@ -674,9 +675,11 @@ int matchStrength(const QString &searchStr, const QString &str)
lastWasSpacer = !thisIsLetterOrNumber;
}
if (i != iEnd)
return iEnd - i;
return i - iEnd;
if (j == jEnd)
++res;
if (!didJump)
res+=2;
return res;
}
......
......@@ -985,13 +985,16 @@ const SemanticInfo &QmlJSCompletionAssistInterface::semanticInfo() const
namespace {
struct QmlJSLessThan
class QmlJSLessThan
{
public:
QmlJSLessThan(const QString &searchString) : m_searchString(searchString)
{ }
bool operator() (const BasicProposalItem *a, const BasicProposalItem *b)
{
if (a->order() != b->order())
return a->order() > b->order();
else if (a->text().isEmpty())
else if (a->text().isEmpty() && ! b->text().isEmpty())
return true;
else if (b->text().isEmpty())
return false;
......@@ -1001,8 +1004,14 @@ struct QmlJSLessThan
return false;
else if (a->text().at(0).isLower() && b->text().at(0).isUpper())
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();
}
private:
QString m_searchString;
};
} // Anonymous
......@@ -1023,9 +1032,9 @@ void QmlJSAssistProposalModel::filter(const QString &prefix)
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
......
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