Skip to content

Commit 61a46e9

Browse files
Maux8DavidLazarescu
authored andcommitted
fixed crash when searching for Booksmarks
1 parent 9a55f38 commit 61a46e9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/adapters/data_models/bookmarks_model/bookmarks_proxy_model.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bool BookmarksProxyModel::lessThan(const QModelIndex& left,
4545
bool BookmarksProxyModel::filterAcceptsRow(
4646
int source_row, const QModelIndex& source_parent) const
4747
{
48-
if(m_filterString.isEmpty())
48+
if(m_filterString.isEmpty() || !m_filterScorer)
4949
return true;
5050

5151
auto index = sourceModel()->index(source_row, 0, source_parent);
@@ -60,7 +60,10 @@ bool BookmarksProxyModel::filterAcceptsRow(
6060

6161
void BookmarksProxyModel::setFilterString(QString newFilterString)
6262
{
63+
6364
m_filterString = newFilterString;
65+
auto input = string_utils::toUtf32(newFilterString);
66+
m_filterScorer = std::make_unique<rapidfuzz::fuzz::CachedRatio<uint32_t>>(input);
6467
emit filterStringUpdated();
6568
invalidate();
6669
}

src/application/utility/string_utils.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,17 @@ inline bool lexicographicallyLess(const QString& left, const QString& right)
5454
return left.toLower() < right.toLower();
5555
}
5656

57+
// QString is utf-16 and needs to be utf-32 for rapidfuzz
58+
inline std::vector<uint32_t> toUtf32(const QString& str)
59+
{
60+
std::vector<uint32_t> result;
61+
result.reserve(str.size());
62+
63+
for (QChar ch : str) {
64+
result.push_back(ch.unicode());
65+
}
66+
67+
return result;
68+
}
69+
5770
} // namespace string_utils

0 commit comments

Comments
 (0)