Completions: move continuations upper in proposals list.

Since fuzzy completions are allowed, the lexicographically first proposal
is not necessarily most relevant. The patch modifies sorting of proposals
so that the exact match and continuations go first, and fuzzy completions
follow.

Moreover, being a continuation seem to be a more important characteristic
of a proposal, than being it a function argument or keyword etc. That's why
the check for continuation is placed before the check for order.

Task-number: QTCREATORBUG-8737
Task-number: QTCREATORBUG-9236
Change-Id: I89aae9d2ce6bfa59af7c2f75e6f3af00212008ca
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: Alexey Zhondin <lexxmark.dev@gmail.com>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
Alexey Semenko
2013-08-28 01:02:26 +04:00
committed by Nikolai Kosjar
parent adee8336bb
commit da4c4b80f3
8 changed files with 80 additions and 11 deletions

View File

@@ -53,16 +53,28 @@ const int kMaxPrefixFilter = 100;
struct ContentLessThan
{
ContentLessThan(const QString &prefix)
: m_prefix(prefix)
{}
bool operator()(const BasicProposalItem *a, const BasicProposalItem *b)
{
// If order is different, show higher ones first.
if (a->order() != b->order())
return a->order() > b->order();
// The order is case-insensitive in principle, but case-sensitive when this
// would otherwise mean equality
const QString &lowera = a->text().toLower();
const QString &lowerb = b->text().toLower();
const QString &lowerprefix = m_prefix.toLower();
// All continuations should go before all fuzzy matches
if (int diff = lowera.startsWith(lowerprefix) - lowerb.startsWith(lowerprefix))
return diff > 0;
if (int diff = a->text().startsWith(m_prefix) - b->text().startsWith(m_prefix))
return diff > 0;
// If order is different, show higher ones first.
if (a->order() != b->order())
return a->order() > b->order();
if (lowera == lowerb)
return lessThan(a->text(), b->text());
else
@@ -113,6 +125,9 @@ struct ContentLessThan
return a < b;
}
};
private:
QString m_prefix;
};
} // Anonymous
@@ -263,9 +278,9 @@ bool BasicProposalItemListModel::isSortable(const QString &prefix) const
return false;
}
void BasicProposalItemListModel::sort()
void BasicProposalItemListModel::sort(const QString &prefix)
{
qStableSort(m_currentItems.begin(), m_currentItems.end(), ContentLessThan());
qStableSort(m_currentItems.begin(), m_currentItems.end(), ContentLessThan(prefix));
}
int BasicProposalItemListModel::persistentId(int index) const