Improve sorting and sizing of completions a bit
This commit is contained in:
parent
b82c11bd79
commit
1961312b15
53 changed files with 95 additions and 121 deletions
|
|
@ -19,6 +19,7 @@ CompletionProxyModel::CompletionProxyModel(QAbstractItemModel *model,
|
|||
setSourceModel(model);
|
||||
QRegularExpression splitPoints("\\s+|-");
|
||||
|
||||
// insert all the full texts
|
||||
for (int i = 0; i < sourceModel()->rowCount(); i++) {
|
||||
if (i < 7)
|
||||
mapping.push_back(i);
|
||||
|
|
@ -29,6 +30,19 @@ CompletionProxyModel::CompletionProxyModel(QAbstractItemModel *model,
|
|||
.toLower();
|
||||
trie_.insert(string1.toUcs4(), i);
|
||||
|
||||
auto string2 = sourceModel()
|
||||
->data(sourceModel()->index(i, 0), CompletionModel::SearchRole2)
|
||||
.toString()
|
||||
.toLower();
|
||||
}
|
||||
|
||||
// insert the partial matches
|
||||
for (int i = 0; i < sourceModel()->rowCount(); i++) {
|
||||
auto string1 = sourceModel()
|
||||
->data(sourceModel()->index(i, 0), CompletionModel::SearchRole)
|
||||
.toString()
|
||||
.toLower();
|
||||
|
||||
for (const auto &e : string1.split(splitPoints)) {
|
||||
if (!e.isEmpty()) // NOTE(Nico): Use Qt::SkipEmptyParts in Qt 5.14
|
||||
trie_.insert(e.toUcs4(), i);
|
||||
|
|
@ -40,7 +54,6 @@ CompletionProxyModel::CompletionProxyModel(QAbstractItemModel *model,
|
|||
.toLower();
|
||||
|
||||
if (!string2.isEmpty()) {
|
||||
trie_.insert(string2.toUcs4(), i);
|
||||
for (const auto &e : string2.split(splitPoints)) {
|
||||
if (!e.isEmpty()) // NOTE(Nico): Use Qt::SkipEmptyParts in Qt 5.14
|
||||
trie_.insert(e.toUcs4(), i);
|
||||
|
|
@ -55,7 +68,7 @@ CompletionProxyModel::CompletionProxyModel(QAbstractItemModel *model,
|
|||
[this](QString s) {
|
||||
s.remove(":");
|
||||
s.remove("@");
|
||||
searchString = s.toLower();
|
||||
searchString_ = s.toLower();
|
||||
invalidate();
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
|
|
@ -64,7 +77,7 @@ CompletionProxyModel::CompletionProxyModel(QAbstractItemModel *model,
|
|||
void
|
||||
CompletionProxyModel::invalidate()
|
||||
{
|
||||
auto key = searchString.toUcs4();
|
||||
auto key = searchString_.toUcs4();
|
||||
beginResetModel();
|
||||
mapping = trie_.search(key, 7, maxMistakes_);
|
||||
endResetModel();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue