From b5a82a4d58551c7e94b56a7edaeb56166a102fc8 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sat, 13 Jul 2019 14:12:28 +0200 Subject: [PATCH] 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 --- .../texteditor/codeassist/assistproposaliteminterface.h | 5 +++-- .../texteditor/codeassist/genericproposalmodel.cpp | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/plugins/texteditor/codeassist/assistproposaliteminterface.h b/src/plugins/texteditor/codeassist/assistproposaliteminterface.h index 893dc4aa0d3..3124b46197c 100644 --- a/src/plugins/texteditor/codeassist/assistproposaliteminterface.h +++ b/src/plugins/texteditor/codeassist/assistproposaliteminterface.h @@ -46,8 +46,9 @@ public: { Full = 0, Exact = 1, - Lower = 2, - None = 3 + Prefix = 2, + Infix = 3, + None = 4 }; AssistProposalItemInterface() = default; diff --git a/src/plugins/texteditor/codeassist/genericproposalmodel.cpp b/src/plugins/texteditor/codeassist/genericproposalmodel.cpp index 29efd1799d2..19e1a0962b2 100644 --- a/src/plugins/texteditor/codeassist/genericproposalmodel.cpp +++ b/src/plugins/texteditor/codeassist/genericproposalmodel.cpp @@ -301,7 +301,10 @@ void GenericProposalModel::filter(const QString &prefix) const QString lowerPrefix = prefix.toLower(); for (const auto &item : qAsConst(m_originalItems)) { 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); if (text.startsWith(prefix)) { // Direct match @@ -312,7 +315,9 @@ void GenericProposalModel::filter(const QString &prefix) } 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); } } }