From 6d715f15d8fea2b0248edfbe20630a8bfe83ad33 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 25 Jan 2024 10:27:35 +0100 Subject: [PATCH] TextEditor: Add case sensitivity checks in optimization 17e2a80e10dfc7907cfe0e95c368710799edd1ef 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 Reviewed-by: Reviewed-by: Christian Kandeler --- .../codeassist/genericproposalmodel.cpp | 48 +++++++++++++++---- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/src/plugins/texteditor/codeassist/genericproposalmodel.cpp b/src/plugins/texteditor/codeassist/genericproposalmodel.cpp index c3ee5261bfb..73f0829d091 100644 --- a/src/plugins/texteditor/codeassist/genericproposalmodel.cpp +++ b/src/plugins/texteditor/codeassist/genericproposalmodel.cpp @@ -295,16 +295,44 @@ void GenericProposalModel::filter(const QString &prefix) continue; } - if (text.startsWith(lowerPrefix, Qt::CaseInsensitive)) { - m_currentItems.append(item); - item->setProposalMatch(AssistProposalItemInterface::ProposalMatch::Prefix); - continue; - } - - if (checkInfix && text.contains(lowerPrefix, Qt::CaseInsensitive)) { - m_currentItems.append(item); - item->setProposalMatch(AssistProposalItemInterface::ProposalMatch::Infix); - continue; + switch (caseSensitivity) { + case FuzzyMatcher::CaseSensitivity::CaseInsensitive: + if (text.startsWith(lowerPrefix, Qt::CaseInsensitive)) { + m_currentItems.append(item); + item->setProposalMatch(AssistProposalItemInterface::ProposalMatch::Prefix); + continue; + } + if (checkInfix && text.contains(lowerPrefix, Qt::CaseInsensitive)) { + m_currentItems.append(item); + 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