Do word splitting in completer
This commit is contained in:
parent
3c208cd717
commit
eae43782a3
@ -6,6 +6,7 @@
|
|||||||
#include "CompletionProxyModel.h"
|
#include "CompletionProxyModel.h"
|
||||||
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
#include <QTextBoundaryFinder>
|
||||||
|
|
||||||
#include "CompletionModelRoles.h"
|
#include "CompletionModelRoles.h"
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
@ -44,27 +45,31 @@ CompletionProxyModel::CompletionProxyModel(QAbstractItemModel *model,
|
|||||||
|
|
||||||
// insert the partial matches
|
// insert the partial matches
|
||||||
for (int i = 0; i < sourceModel()->rowCount(); i++) {
|
for (int i = 0; i < sourceModel()->rowCount(); i++) {
|
||||||
auto string1 = sourceModel()
|
auto insertParts = [i, this](const QString &str) {
|
||||||
->data(sourceModel()->index(i, 0), CompletionModel::SearchRole)
|
if (str.isEmpty())
|
||||||
.toString()
|
return;
|
||||||
.toLower();
|
|
||||||
|
|
||||||
auto split1 = QStringView(string1).split(splitPoints, Qt::SkipEmptyParts);
|
QTextBoundaryFinder finder(QTextBoundaryFinder::BoundaryType::Word, str);
|
||||||
for (const auto &e : qAsConst(split1)) {
|
finder.toStart();
|
||||||
trie_.insert(e.toUcs4(), i);
|
do {
|
||||||
}
|
auto start = finder.position();
|
||||||
|
finder.toNextBoundary();
|
||||||
|
auto end = finder.position();
|
||||||
|
|
||||||
auto string2 = sourceModel()
|
auto ref = str.midRef(start, end - start).trimmed();
|
||||||
->data(sourceModel()->index(i, 0), CompletionModel::SearchRole2)
|
if (!ref.isEmpty())
|
||||||
.toString()
|
trie_.insert(ref.toUcs4(), i);
|
||||||
.toLower();
|
} while (finder.position() < str.size());
|
||||||
|
};
|
||||||
|
|
||||||
if (!string2.isEmpty()) {
|
insertParts(sourceModel()
|
||||||
auto split2 = QStringView(string2).split(splitPoints, Qt::SkipEmptyParts);
|
->data(sourceModel()->index(i, 0), CompletionModel::SearchRole)
|
||||||
for (const auto &e : qAsConst(split2)) {
|
.toString()
|
||||||
trie_.insert(e.toUcs4(), i);
|
.toLower());
|
||||||
}
|
insertParts(sourceModel()
|
||||||
}
|
->data(sourceModel()->index(i, 0), CompletionModel::SearchRole2)
|
||||||
|
.toString()
|
||||||
|
.toLower());
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(
|
connect(
|
||||||
|
Loading…
Reference in New Issue
Block a user