TextEditor: Add case sensitivity checks in optimization

17e2a80e10 added some optimization for
prefix and infix matches of completion items in order to avoid the
expensive regular expression check for the fuzzy match, but ignored the
user configured case sensitivity for auto completions.

Change-Id: Ic340e48abc6636bd2e8abeeddcd880cbdc66d03e
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
David Schulz
2024-01-25 10:27:35 +01:00
parent a8370aaf81
commit 6d715f15d8

View File

@@ -295,16 +295,44 @@ void GenericProposalModel::filter(const QString &prefix)
continue; continue;
} }
if (text.startsWith(lowerPrefix, Qt::CaseInsensitive)) { switch (caseSensitivity) {
m_currentItems.append(item); case FuzzyMatcher::CaseSensitivity::CaseInsensitive:
item->setProposalMatch(AssistProposalItemInterface::ProposalMatch::Prefix); if (text.startsWith(lowerPrefix, Qt::CaseInsensitive)) {
continue; m_currentItems.append(item);
} item->setProposalMatch(AssistProposalItemInterface::ProposalMatch::Prefix);
continue;
if (checkInfix && text.contains(lowerPrefix, Qt::CaseInsensitive)) { }
m_currentItems.append(item); if (checkInfix && text.contains(lowerPrefix, Qt::CaseInsensitive)) {
item->setProposalMatch(AssistProposalItemInterface::ProposalMatch::Infix); m_currentItems.append(item);
continue; item->setProposalMatch(AssistProposalItemInterface::ProposalMatch::Infix);
continue;
}
break;
case FuzzyMatcher::CaseSensitivity::CaseSensitive:
if (checkInfix && text.contains(prefix)) {
m_currentItems.append(item);
item->setProposalMatch(AssistProposalItemInterface::ProposalMatch::Infix);
continue;
}
break;
case FuzzyMatcher::CaseSensitivity::FirstLetterCaseSensitive:
if (text.startsWith(prefix.at(0))
&& text.mid(1).startsWith(lowerPrefix.mid(1), Qt::CaseInsensitive)) {
m_currentItems.append(item);
item->setProposalMatch(AssistProposalItemInterface::ProposalMatch::Prefix);
continue;
}
if (checkInfix) {
for (auto index = text.indexOf(prefix.at(0)); index >= 0;
index = text.indexOf(prefix.at(0), index + 1)) {
if (text.mid(index + 1).startsWith(lowerPrefix.mid(1), Qt::CaseInsensitive)) {
m_currentItems.append(item);
item->setProposalMatch(AssistProposalItemInterface::ProposalMatch::Infix);
continue;
}
}
}
break;
} }
// Our fuzzy matcher can become unusably slow with certain inputs, so skip it // Our fuzzy matcher can become unusably slow with certain inputs, so skip it