forked from qt-creator/qt-creator
GenericProposalModel: Allow substring matches
So far, if we had these three functions:
int getSomething() { return 44; }
int get_something() { return 43; }
int something() { return 42; }
then we did not get a completion for getSomething()
or get_something() if we just typed "some", as only
the prefix was taken into account.
This patch adds support for substring matches, and
adds these with lower priority to the proposal list.
Task-number: QTCREATORBUG-19170
Fixes: QTCREATORBUG-19918
Change-Id: Ifc5e2149e4b1fa995f1f8550efc84e7ff4fb1522
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
committed by
André Hartmann
parent
20cccf53ae
commit
b5a82a4d58
@@ -46,8 +46,9 @@ public:
|
|||||||
{
|
{
|
||||||
Full = 0,
|
Full = 0,
|
||||||
Exact = 1,
|
Exact = 1,
|
||||||
Lower = 2,
|
Prefix = 2,
|
||||||
None = 3
|
Infix = 3,
|
||||||
|
None = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
AssistProposalItemInterface() = default;
|
AssistProposalItemInterface() = default;
|
||||||
|
|||||||
@@ -301,7 +301,10 @@ void GenericProposalModel::filter(const QString &prefix)
|
|||||||
const QString lowerPrefix = prefix.toLower();
|
const QString lowerPrefix = prefix.toLower();
|
||||||
for (const auto &item : qAsConst(m_originalItems)) {
|
for (const auto &item : qAsConst(m_originalItems)) {
|
||||||
const QString &text = item->text();
|
const QString &text = item->text();
|
||||||
if (regExp.match(text).capturedStart() == 0) {
|
const QRegularExpressionMatch match = regExp.match(text);
|
||||||
|
const bool hasPrefixMatch = match.capturedStart() == 0;
|
||||||
|
const bool hasInfixMatch = prefix.size() >= 3 && match.hasMatch();
|
||||||
|
if (hasPrefixMatch || hasInfixMatch) {
|
||||||
m_currentItems.append(item);
|
m_currentItems.append(item);
|
||||||
if (text.startsWith(prefix)) {
|
if (text.startsWith(prefix)) {
|
||||||
// Direct match
|
// Direct match
|
||||||
@@ -312,7 +315,9 @@ void GenericProposalModel::filter(const QString &prefix)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (text.startsWith(lowerPrefix, Qt::CaseInsensitive))
|
if (text.startsWith(lowerPrefix, Qt::CaseInsensitive))
|
||||||
item->setPrefixMatch(AssistProposalItemInterface::PrefixMatch::Lower);
|
item->setPrefixMatch(AssistProposalItemInterface::PrefixMatch::Prefix);
|
||||||
|
else if (text.contains(lowerPrefix, Qt::CaseInsensitive))
|
||||||
|
item->setPrefixMatch(AssistProposalItemInterface::PrefixMatch::Infix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user