forked from qt-creator/qt-creator
Locator: Add camel hump locator filter for C++, QML, and files
* Use the CamelHumpMatcher in the C++, QML, and files filters * Supports matching against UpperCamelCase, lowerCamelCase and snake_case strings * Supports highlighting of matched characters Task-number: QTCREATORBUG-3111 Started-by: David Kaspar <dkaspar@blackberry.com> Change-Id: If6220191432ef965bde3c8dbe4a10d89e222ba6f Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
committed by
André Hartmann
parent
2fb54abd03
commit
632f2a7709
@@ -28,9 +28,9 @@
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/camelhumpmatcher.h>
|
||||
|
||||
#include <QRegExp>
|
||||
#include <QStringMatcher>
|
||||
#include <QRegularExpression>
|
||||
|
||||
using namespace QmlJSTools::Internal;
|
||||
|
||||
@@ -59,12 +59,13 @@ QList<Core::LocatorFilterEntry> FunctionFilter::matchesFor(
|
||||
{
|
||||
QList<Core::LocatorFilterEntry> goodEntries;
|
||||
QList<Core::LocatorFilterEntry> betterEntries;
|
||||
const Qt::CaseSensitivity cs = caseSensitivity(entry);
|
||||
QStringMatcher matcher(entry, cs);
|
||||
QRegExp regexp(entry, cs, QRegExp::Wildcard);
|
||||
QList<Core::LocatorFilterEntry> bestEntries;
|
||||
const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry);
|
||||
const QRegularExpression regexp = containsWildcard(entry)
|
||||
? createWildcardRegExp(entry) : CamelHumpMatcher::createCamelHumpRegExp(entry);
|
||||
|
||||
if (!regexp.isValid())
|
||||
return goodEntries;
|
||||
bool hasWildcard = containsWildcard(entry);
|
||||
|
||||
QHashIterator<QString, QList<LocatorData::Entry> > it(m_data->entries());
|
||||
while (it.hasNext()) {
|
||||
@@ -78,16 +79,19 @@ QList<Core::LocatorFilterEntry> FunctionFilter::matchesFor(
|
||||
if (info.type != LocatorData::Function)
|
||||
continue;
|
||||
|
||||
const int index = hasWildcard ? regexp.indexIn(info.symbolName)
|
||||
: matcher.indexIn(info.symbolName);
|
||||
if (index >= 0) {
|
||||
const QRegularExpressionMatch match = regexp.match(info.symbolName);
|
||||
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;
|
||||
const int length = hasWildcard ? regexp.matchedLength() : entry.length();
|
||||
filterEntry.highlightInfo = {index, length};
|
||||
filterEntry.highlightInfo.starts = positions.starts;
|
||||
filterEntry.highlightInfo.lengths = positions.lengths;
|
||||
|
||||
if (index == 0)
|
||||
if (filterEntry.displayName.startsWith(entry, caseSensitivityForPrefix))
|
||||
bestEntries.append(filterEntry);
|
||||
else if (filterEntry.displayName.contains(entry, caseSensitivityForPrefix))
|
||||
betterEntries.append(filterEntry);
|
||||
else
|
||||
goodEntries.append(filterEntry);
|
||||
@@ -99,9 +103,12 @@ QList<Core::LocatorFilterEntry> FunctionFilter::matchesFor(
|
||||
Utils::sort(goodEntries, Core::LocatorFilterEntry::compareLexigraphically);
|
||||
if (betterEntries.size() < 1000)
|
||||
Utils::sort(betterEntries, Core::LocatorFilterEntry::compareLexigraphically);
|
||||
if (bestEntries.size() < 1000)
|
||||
Utils::sort(bestEntries, Core::LocatorFilterEntry::compareLexigraphically);
|
||||
|
||||
betterEntries += goodEntries;
|
||||
return betterEntries;
|
||||
bestEntries += betterEntries;
|
||||
bestEntries += goodEntries;
|
||||
return bestEntries;
|
||||
}
|
||||
|
||||
void FunctionFilter::accept(Core::LocatorFilterEntry selection,
|
||||
|
||||
Reference in New Issue
Block a user