diff options
author | Andre Hartmann <aha_1980@gmx.de> | 2017-12-29 07:57:01 +0100 |
---|---|---|
committer | André Hartmann <aha_1980@gmx.de> | 2018-01-03 10:39:30 +0000 |
commit | adc8638de0bceafad65555e4f249e88883be01bb (patch) | |
tree | 423bf81b74146cac8f474c46258b0a6688ca80f9 /src/plugins/coreplugin/locator/basefilefilter.cpp | |
parent | 8e92c285737e3ac85e58186ec7c7efdf37b82268 (diff) |
BaseFileFilter: Rate full matches higher than fuzzy matches
Searching for "qmap.h" should not have "qcore_mac_p.h" as
first search result and "qmap.h" somewhere later in the list.
This is only a partial solution for QTCREATORBUG-19531, as the
filter might be called multiple times (for "All Included Files"
and "Files in Any Project"). So the final result list may contain
the best results in the middle.
Task-number: QTCREATORBUG-19531
Change-Id: Ib5322824d3e0e8106c2f197169342f18923a894a
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/plugins/coreplugin/locator/basefilefilter.cpp')
-rw-r--r-- | src/plugins/coreplugin/locator/basefilefilter.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/plugins/coreplugin/locator/basefilefilter.cpp b/src/plugins/coreplugin/locator/basefilefilter.cpp index 39f4d003347..20535286876 100644 --- a/src/plugins/coreplugin/locator/basefilefilter.cpp +++ b/src/plugins/coreplugin/locator/basefilefilter.cpp @@ -93,17 +93,31 @@ void BaseFileFilter::prepareSearch(const QString &entry) d->m_data.forceNewSearchList = false; } +static int matchLevelFor(const QRegularExpressionMatch &match, const QString &matchText) +{ + const int consecutivePos = match.capturedStart(1); + if (consecutivePos == 0) + return 0; + if (consecutivePos > 0) { + const QChar prevChar = matchText.at(consecutivePos - 1); + if (prevChar == '_' || prevChar == '.') + return 1; + } + if (match.capturedStart() == 0) + return 2; + return 3; +} + QList<LocatorFilterEntry> BaseFileFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &future, const QString &origEntry) { - QList<LocatorFilterEntry> betterEntries; - QList<LocatorFilterEntry> goodEntries; + QList<LocatorFilterEntry> entries[4]; const QString entry = QDir::fromNativeSeparators(origEntry); const EditorManager::FilePathInfo fp = EditorManager::splitLineAndColumnNumber(entry); const QRegularExpression regexp = createRegExp(fp.filePath); if (!regexp.isValid()) { d->m_current.clear(); // free memory - return betterEntries; + return entries[0]; } const QChar pathSeparator('/'); const bool hasPathSeparator = fp.filePath.contains(pathSeparator); @@ -141,7 +155,7 @@ QList<LocatorFilterEntry> BaseFileFilter::matchesFor(QFutureInterface<LocatorFil filterEntry.fileName = path; filterEntry.extraInfo = FileUtils::shortNativePath(FileName(fi)); - const bool betterMatch = match.capturedStart() == 0; + const int matchLevel = matchLevelFor(match, matchText); if (hasPathSeparator) { match = regexp.match(filterEntry.extraInfo); filterEntry.highlightInfo = @@ -150,16 +164,12 @@ QList<LocatorFilterEntry> BaseFileFilter::matchesFor(QFutureInterface<LocatorFil filterEntry.highlightInfo = highlightInfo(match); } - if (betterMatch) - betterEntries.append(filterEntry); - else - goodEntries.append(filterEntry); + entries[matchLevel].append(filterEntry); d->m_current.previousResultPaths.append(path); d->m_current.previousResultNames.append(name); } } - betterEntries.append(goodEntries); if (canceled) { // we keep the old list of previous search results if this search was canceled // so a later search without forceNewSearchList will use that previous list instead of an @@ -169,7 +179,7 @@ QList<LocatorFilterEntry> BaseFileFilter::matchesFor(QFutureInterface<LocatorFil d->m_current.iterator.clear(); QTimer::singleShot(0, this, &BaseFileFilter::updatePreviousResultData); } - return betterEntries; + return entries[0] + entries[1] + entries[2] + entries[3]; } void BaseFileFilter::accept(LocatorFilterEntry selection, |