Skip to content
Snippets Groups Projects
Verified Commit eae43782 authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Do word splitting in completer

parent 3c208cd7
No related branches found
No related tags found
No related merge requests found
Pipeline #2554 failed
......@@ -6,6 +6,7 @@
#include "CompletionProxyModel.h"
#include <QRegularExpression>
#include <QTextBoundaryFinder>
#include "CompletionModelRoles.h"
#include "Logging.h"
......@@ -44,27 +45,31 @@ CompletionProxyModel::CompletionProxyModel(QAbstractItemModel *model,
// insert the partial matches
for (int i = 0; i < sourceModel()->rowCount(); i++) {
auto string1 = sourceModel()
->data(sourceModel()->index(i, 0), CompletionModel::SearchRole)
.toString()
.toLower();
auto split1 = QStringView(string1).split(splitPoints, Qt::SkipEmptyParts);
for (const auto &e : qAsConst(split1)) {
trie_.insert(e.toUcs4(), i);
}
auto string2 = sourceModel()
->data(sourceModel()->index(i, 0), CompletionModel::SearchRole2)
.toString()
.toLower();
if (!string2.isEmpty()) {
auto split2 = QStringView(string2).split(splitPoints, Qt::SkipEmptyParts);
for (const auto &e : qAsConst(split2)) {
trie_.insert(e.toUcs4(), i);
}
}
auto insertParts = [i, this](const QString &str) {
if (str.isEmpty())
return;
QTextBoundaryFinder finder(QTextBoundaryFinder::BoundaryType::Word, str);
finder.toStart();
do {
auto start = finder.position();
finder.toNextBoundary();
auto end = finder.position();
auto ref = str.midRef(start, end - start).trimmed();
if (!ref.isEmpty())
trie_.insert(ref.toUcs4(), i);
} while (finder.position() < str.size());
};
insertParts(sourceModel()
->data(sourceModel()->index(i, 0), CompletionModel::SearchRole)
.toString()
.toLower());
insertParts(sourceModel()
->data(sourceModel()->index(i, 0), CompletionModel::SearchRole2)
.toString()
.toLower());
}
connect(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment