summary refs log tree commit diff
path: root/src/CompletionProxyModel.h
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2023-05-06 19:30:29 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2023-05-06 19:30:29 +0200
commit7dd333947711b9ebb54460066a25b07d155fa012 (patch)
treee7879c87bad2f2d23349de37a5c2a722b685bf1e /src/CompletionProxyModel.h
parentAllow picking multiple files to upload (diff)
downloadnheko-7dd333947711b9ebb54460066a25b07d155fa012.tar.xz
Sort rooms in completer by 'activity' and make tombstoned rooms italic
Diffstat (limited to 'src/CompletionProxyModel.h')
-rw-r--r--src/CompletionProxyModel.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/CompletionProxyModel.h b/src/CompletionProxyModel.h

index e0f00788..a72b1d0a 100644 --- a/src/CompletionProxyModel.h +++ b/src/CompletionProxyModel.h
@@ -8,6 +8,8 @@ #include <QAbstractProxyModel> +#include <algorithm> + enum class ElementRank { first, @@ -17,7 +19,7 @@ enum class ElementRank template<typename Key, typename Value> struct trie { - std::vector<Value> values; + std::vector<std::pair<ElementRank, Value>> values; std::map<Key, trie> next; template<ElementRank r> @@ -29,9 +31,11 @@ struct trie } if constexpr (r == ElementRank::first) { - t->values.insert(t->values.begin(), v); + auto it = + std::ranges::upper_bound(t->values, r, {}, &std::pair<ElementRank, Value>::first); + t->values.emplace(it, r, v); } else if constexpr (r == ElementRank::second) { - t->values.push_back(v); + t->values.emplace_back(r, v); } } @@ -45,7 +49,7 @@ struct trie if (ret.size() >= limit) return ret; else - ret.push_back(v); + ret.push_back(v.second); } for (const auto &[k, t] : next) {