Commit 34bb6dca authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Move away from interal fuzzy algo to KFuzzyMatcher

For most places, the internal algorithm is not needed. We can just the
KCoreAddons one directly.
parent 5a345b58
Pipeline #239321 canceled with stage
in 7 minutes and 20 seconds
......@@ -7,6 +7,7 @@
#include "lspclientsymbolview.h"
#include <KFuzzyMatcher>
#include <KLineEdit>
#include <KLocalizedString>
#include <QSortFilterProxyModel>
......@@ -27,8 +28,6 @@
#include <memory>
#include <utility>
#include <kfts_fuzzy_match.h>
// TODO: Make this globally available in shared/
enum SymbolViewRoles { SymbolRange = Qt::UserRole, ScoreRole, IsPlaceholder };
......@@ -148,12 +147,11 @@ protected:
return true;
}
int score = 0;
const auto idx = sourceModel()->index(sourceRow, 0, sourceParent);
const QString symbol = idx.data().toString();
const bool res = kfts::fuzzy_match(m_pattern, symbol, score);
sourceModel()->setData(idx, score, SymbolViewRoles::ScoreRole);
return res;
const auto res = KFuzzyMatcher::match(m_pattern, symbol);
sourceModel()->setData(idx, res.score, SymbolViewRoles::ScoreRole);
return res.matched;
}
private:
......
......@@ -13,13 +13,12 @@
#include <QTreeView>
#include <QWidget>
#include <KFuzzyMatcher>
#include <KLocalizedString>
#include <KTextEditor/Message>
#include <KTextEditor/View>
#include <KLocalizedString>
#include <drawing_utils.h>
#include <kfts_fuzzy_match.h>
class StyleDelegate : public HUDStyleDelegate
{
......@@ -42,7 +41,10 @@ public:
const bool branchItem = itemType == BranchesDialogModel::BranchItem;
const int offset = branchItem ? 0 : 2;
formats = kfts::get_fuzzy_match_formats(m_filterString, name, offset, fmt);
const auto ranges = KFuzzyMatcher::matchedRanges(m_filterString, name);
std::transform(ranges.begin(), ranges.end(), std::back_inserter(formats), [offset, fmt](const KFuzzyMatcher::Range &fr) {
return QTextLayout::FormatRange{fr.start + offset, fr.length, fmt};
});
if (!branchItem) {
name = QStringLiteral("+ ") + name;
......
......@@ -43,6 +43,7 @@
#include <KLocalizedString>
#include <KMessageBox>
#include <KFuzzyMatcher>
#include <KSyntaxHighlighting/Definition>
#include <KSyntaxHighlighting/Repository>
#include <KTextEditor/Editor>
......@@ -50,9 +51,6 @@
#include <KTextEditor/Message>
#include <KTextEditor/View>
#include <kfts_fuzzy_match.h>
#include <qkeysequence.h>
class NumStatStyle final : public QStyledItemDelegate
{
public:
......@@ -147,8 +145,8 @@ public:
}
const QString file = index.data().toString();
int s = 0; // not using score atm
return kfts::fuzzy_match(m_text, file, s);
// not using score atm
return KFuzzyMatcher::matchSimple(m_text, file);
}
void setFilterText(const QString &text)
......
......@@ -11,7 +11,7 @@
#include <QSortFilterProxyModel>
#include <kfts_fuzzy_match.h>
#include <KFuzzyMatcher>
class KateProjectFilterProxyModel : public QSortFilterProxyModel
{
......@@ -44,7 +44,7 @@ protected:
}
const QString file = index.data().toString();
return kfts::fuzzy_match_simple(m_pattern, file);
return KFuzzyMatcher::matchSimple(m_pattern, file);
}
private:
......
......@@ -17,7 +17,6 @@
#include <KLocalizedString>
#include <drawing_utils.h>
#include <kfts_fuzzy_match.h>
#include <gitprocess.h>
......
......@@ -40,17 +40,17 @@
#include "plugin_katesymbolviewer.h"
#include <KConfigGroup>
#include <KFuzzyMatcher>
#include <KLineEdit>
#include <KPluginFactory>
#include <KSharedConfig>
#include <KXMLGUIFactory>
#include <QAction>
#include <QKeyEvent>
#include <ktexteditor/configinterface.h>
#include <ktexteditor/cursor.h>
#include <kfts_fuzzy_match.h>
#include <QGroupBox>
#include <QVBoxLayout>
......@@ -411,7 +411,7 @@ bool KatePluginSymbolViewerView::filterSymbols(QTreeWidgetItem *item, const QStr
at_least_one_child_shown = true;
}
}
bool is_item_match = kfts::fuzzy_match_simple(filter, item->text(0));
bool is_item_match = KFuzzyMatcher::matchSimple(filter, item->text(0));
bool is_item_shown = at_least_one_child_shown || filter.isEmpty() || is_item_match;
item->setHidden(!is_item_shown);
return is_item_shown;
......
......@@ -24,7 +24,7 @@
#include <QTreeView>
#include <QVBoxLayout>
#include <kfts_fuzzy_match.h>
#include <KFuzzyMatcher>
#include <ktexteditor_utils.h>
class KateOutputTreeView : public QTreeView
......@@ -145,15 +145,13 @@ protected:
const QString type = idxType.data().toString();
const QString body = idxBody.data().toString();
int scorec = 0;
int scoret = 0;
const bool resc = kfts::fuzzy_match(m_pattern, cat, scorec);
const bool rest = kfts::fuzzy_match(m_pattern, type, scoret);
const auto resc = KFuzzyMatcher::match(m_pattern, cat);
const auto rest = KFuzzyMatcher::match(m_pattern, type);
const bool resb = body.contains(m_pattern, Qt::CaseInsensitive);
const auto idx = sourceModel()->index(sourceRow, KateOutputView::Column_Time, sourceParent);
sourceModel()->setData(idx, scorec + scoret, WeightRole);
return resc || rest || resb;
sourceModel()->setData(idx, resc.score + rest.score, WeightRole);
return resc.matched || rest.matched || resb;
}
private:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment