forked from qt-creator/qt-creator
Locator: De-duplicate highlightInfo generation for camel humps
Change-Id: I5a3fd28ddd68b2ac17a76384cffad12064d06259 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
committed by
André Hartmann
parent
4d3ea43dbc
commit
62d971b30b
@@ -26,7 +26,6 @@
|
||||
#include "basefilefilter.h"
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <utils/camelhumpmatcher.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
@@ -142,16 +141,14 @@ QList<LocatorFilterEntry> BaseFileFilter::matchesFor(QFutureInterface<LocatorFil
|
||||
filterEntry.fileName = path;
|
||||
filterEntry.extraInfo = FileUtils::shortNativePath(FileName(fi));
|
||||
|
||||
LocatorFilterEntry::HighlightInfo::DataType hDataType = LocatorFilterEntry::HighlightInfo::DisplayName;
|
||||
const bool betterMatch = match.capturedStart() == 0;
|
||||
if (hasPathSeparator) {
|
||||
match = regexp.match(filterEntry.extraInfo);
|
||||
hDataType = LocatorFilterEntry::HighlightInfo::ExtraInfo;
|
||||
filterEntry.highlightInfo =
|
||||
highlightInfo(match, LocatorFilterEntry::HighlightInfo::ExtraInfo);
|
||||
} else {
|
||||
filterEntry.highlightInfo = highlightInfo(match);
|
||||
}
|
||||
const CamelHumpMatcher::HighlightingPositions positions =
|
||||
CamelHumpMatcher::highlightingPositions(match);
|
||||
filterEntry.highlightInfo =
|
||||
LocatorFilterEntry::HighlightInfo(positions.starts, positions.lengths, hDataType);
|
||||
|
||||
if (betterMatch)
|
||||
betterEntries.append(filterEntry);
|
||||
|
@@ -228,6 +228,15 @@ QRegularExpression ILocatorFilter::createRegExp(const QString &text)
|
||||
: CamelHumpMatcher::createCamelHumpRegExp(text);
|
||||
}
|
||||
|
||||
LocatorFilterEntry::HighlightInfo ILocatorFilter::highlightInfo(
|
||||
const QRegularExpressionMatch &match, LocatorFilterEntry::HighlightInfo::DataType dataType)
|
||||
{
|
||||
const CamelHumpMatcher::HighlightingPositions positions =
|
||||
CamelHumpMatcher::highlightingPositions(match);
|
||||
|
||||
return LocatorFilterEntry::HighlightInfo(positions.starts, positions.lengths, dataType);
|
||||
}
|
||||
|
||||
/*!
|
||||
Specifies a title for configuration dialogs.
|
||||
*/
|
||||
|
@@ -145,6 +145,8 @@ public:
|
||||
static Qt::CaseSensitivity caseSensitivity(const QString &str);
|
||||
static bool containsWildcard(const QString &str);
|
||||
static QRegularExpression createRegExp(const QString &text);
|
||||
LocatorFilterEntry::HighlightInfo highlightInfo(const QRegularExpressionMatch &match,
|
||||
LocatorFilterEntry::HighlightInfo::DataType dataType = LocatorFilterEntry::HighlightInfo::DisplayName);
|
||||
|
||||
static QString msgConfigureDialogTitle();
|
||||
static QString msgPrefixLabel();
|
||||
|
@@ -27,7 +27,6 @@
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <utils/camelhumpmatcher.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
@@ -75,13 +74,10 @@ QList<LocatorFilterEntry> OpenDocumentsFilter::matchesFor(QFutureInterface<Locat
|
||||
QString displayName = editorEntry.displayName;
|
||||
const QRegularExpressionMatch match = regexp.match(displayName);
|
||||
if (match.hasMatch()) {
|
||||
const CamelHumpMatcher::HighlightingPositions positions =
|
||||
CamelHumpMatcher::highlightingPositions(match);
|
||||
LocatorFilterEntry filterEntry(this, displayName, QString(fileName + fp.postfix));
|
||||
filterEntry.extraInfo = FileUtils::shortNativePath(FileName::fromString(fileName));
|
||||
filterEntry.fileName = fileName;
|
||||
filterEntry.highlightInfo.starts = positions.starts;
|
||||
filterEntry.highlightInfo.lengths = positions.lengths;
|
||||
filterEntry.highlightInfo = highlightInfo(match);
|
||||
if (match.capturedStart() == 0)
|
||||
betterEntries.append(filterEntry);
|
||||
else
|
||||
|
@@ -30,7 +30,6 @@
|
||||
#include <coreplugin/idocument.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <utils/camelhumpmatcher.h>
|
||||
|
||||
#include <QRegularExpression>
|
||||
|
||||
@@ -96,14 +95,13 @@ QList<Core::LocatorFilterEntry> CppCurrentDocumentFilter::matchesFor(
|
||||
|
||||
Core::LocatorFilterEntry filterEntry(this, name, id, info->icon());
|
||||
filterEntry.extraInfo = extraInfo;
|
||||
if (!match.hasMatch()) {
|
||||
if (match.hasMatch()) {
|
||||
filterEntry.highlightInfo = highlightInfo(match);
|
||||
} else {
|
||||
match = regexp.match(extraInfo);
|
||||
filterEntry.highlightInfo.dataType = Core::LocatorFilterEntry::HighlightInfo::ExtraInfo;
|
||||
filterEntry.highlightInfo =
|
||||
highlightInfo(match, Core::LocatorFilterEntry::HighlightInfo::ExtraInfo);
|
||||
}
|
||||
const CamelHumpMatcher::HighlightingPositions positions =
|
||||
CamelHumpMatcher::highlightingPositions(match);
|
||||
filterEntry.highlightInfo.starts = positions.starts;
|
||||
filterEntry.highlightInfo.lengths = positions.lengths;
|
||||
|
||||
if (betterMatch)
|
||||
betterEntries.append(filterEntry);
|
||||
|
@@ -28,7 +28,6 @@
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/camelhumpmatcher.h>
|
||||
|
||||
#include <QRegularExpression>
|
||||
|
||||
@@ -94,10 +93,7 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
|
||||
// to update the match if the displayName is different from matchString
|
||||
if (matchString != filterEntry.displayName)
|
||||
match = regexp.match(filterEntry.displayName);
|
||||
const CamelHumpMatcher::HighlightingPositions positions =
|
||||
CamelHumpMatcher::highlightingPositions(match);
|
||||
filterEntry.highlightInfo.starts = positions.starts;
|
||||
filterEntry.highlightInfo.lengths = positions.lengths;
|
||||
filterEntry.highlightInfo = highlightInfo(match);
|
||||
|
||||
if (matchString.startsWith(entry, caseSensitivityForPrefix))
|
||||
bestEntries.append(filterEntry);
|
||||
|
@@ -28,7 +28,6 @@
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/camelhumpmatcher.h>
|
||||
|
||||
#include <QRegularExpression>
|
||||
|
||||
@@ -82,11 +81,8 @@ QList<Core::LocatorFilterEntry> FunctionFilter::matchesFor(
|
||||
if (match.hasMatch()) {
|
||||
QVariant id = qVariantFromValue(info);
|
||||
Core::LocatorFilterEntry filterEntry(this, info.displayName, id/*, info.icon*/);
|
||||
const CamelHumpMatcher::HighlightingPositions positions =
|
||||
CamelHumpMatcher::highlightingPositions(match);
|
||||
filterEntry.extraInfo = info.extraInfo;
|
||||
filterEntry.highlightInfo.starts = positions.starts;
|
||||
filterEntry.highlightInfo.lengths = positions.lengths;
|
||||
filterEntry.highlightInfo = highlightInfo(match);
|
||||
|
||||
if (filterEntry.displayName.startsWith(entry, caseSensitivityForPrefix))
|
||||
bestEntries.append(filterEntry);
|
||||
|
Reference in New Issue
Block a user