From 370511b5e469039230888b9a7c415d695224d398 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sat, 13 Jul 2019 06:52:11 +0200 Subject: [PATCH] BaseFileFilter: Make searching in paths easier Allow searching for TextEditor/main.cpp by typing either "text*main" or simply "text main". Fixes: QTCREATORBUG-22546 Change-Id: Ica6fbd67c98381a8b2d13801e93ef7dba7f367a4 Reviewed-by: Eike Ziller --- src/plugins/coreplugin/locator/basefilefilter.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/plugins/coreplugin/locator/basefilefilter.cpp b/src/plugins/coreplugin/locator/basefilefilter.cpp index e2b26b57ae7..57c5018dd0a 100644 --- a/src/plugins/coreplugin/locator/basefilefilter.cpp +++ b/src/plugins/coreplugin/locator/basefilefilter.cpp @@ -111,7 +111,8 @@ static int matchLevelFor(const QRegularExpressionMatch &match, const QString &ma QList BaseFileFilter::matchesFor(QFutureInterface &future, const QString &origEntry) { QList entries[4]; - const QString entry = QDir::fromNativeSeparators(origEntry); + // If search string contains spaces, treat them as wildcard '*' and search in full path + const QString entry = QDir::fromNativeSeparators(origEntry).replace(' ', '*'); const EditorManager::FilePathInfo fp = EditorManager::splitLineAndColumnNumber(entry); const QRegularExpression regexp = createRegExp(fp.filePath); @@ -119,12 +120,15 @@ QList BaseFileFilter::matchesFor(QFutureInterfacem_current.clear(); // free memory return entries[0]; } - const QChar pathSeparator('/'); - const bool hasPathSeparator = fp.filePath.contains(pathSeparator); + auto containsPathSeparator = [](const QString &candidate) { + return candidate.contains('/') || candidate.contains('*'); + }; + + const bool hasPathSeparator = containsPathSeparator(fp.filePath); const bool containsPreviousEntry = !d->m_current.previousEntry.isEmpty() && fp.filePath.contains(d->m_current.previousEntry); - const bool pathSeparatorAdded = !d->m_current.previousEntry.contains(pathSeparator) - && fp.filePath.contains(pathSeparator); + const bool pathSeparatorAdded = !containsPathSeparator(d->m_current.previousEntry) + && hasPathSeparator; const bool searchInPreviousResults = !d->m_current.forceNewSearchList && containsPreviousEntry && !pathSeparatorAdded; if (searchInPreviousResults)